Skip to content

Commit

Permalink
Added name field to irrigation program
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewpetro committed Mar 3, 2024
1 parent f2b511c commit bf5d2ff
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/irrigation-programs/dto/create-irrigation-program.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { IsBoolean, IsISO8601, IsInt, IsOptional, IsPositive, Matches } from 'class-validator'
import { IsBoolean, IsISO8601, IsInt, IsOptional, IsPositive, Length, Matches } from 'class-validator'

export class CreateIrrigationProgramDto {
@Length(1, 255)
name: string

@IsInt()
@IsPositive()
duration: number
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export class IrrigationProgramEntity {
constructor(
public readonly name: string,
public readonly duration: number,
public readonly wateringPeriod: number,
public readonly startTime: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface IrrigationProgram {
id: string
name: string
duration: number
wateringPeriod: number
startTime: string
Expand Down
9 changes: 9 additions & 0 deletions src/irrigation-programs/irrigation-programs.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe('IrrigationProgramsService', () => {
it('should create an irrigation program', async () => {
mockInsert.mockResolvedValue({ id: uuidv4(), ok: true })
const mockCreateDto: CreateIrrigationProgramDto = {
name: 'Irrigation Program 1',
duration: 10,
wateringPeriod: 2,
startTime: '12:00',
Expand All @@ -84,6 +85,7 @@ describe('IrrigationProgramsService', () => {
it('should not create an irrigation program because the result is not ok', async () => {
mockInsert.mockResolvedValue({ ok: false })
const mockCreateDto: CreateIrrigationProgramDto = {
name: 'Irrigation Program 1',
duration: 10,
wateringPeriod: 2,
startTime: '12:00',
Expand All @@ -101,6 +103,7 @@ describe('IrrigationProgramsService', () => {
it('should not create an irrigation program because the database throws an error', async () => {
mockInsert.mockRejectedValue({})
const mockCreateDto: CreateIrrigationProgramDto = {
name: 'Irrigation Program 1',
duration: 10,
wateringPeriod: 2,
startTime: '12:00',
Expand All @@ -119,13 +122,15 @@ describe('IrrigationProgramsService', () => {
describe('get all irrigation programs', () => {
it('should find all irrigation programs', async () => {
const mockIrrigationProgram1 = {
name: 'Irrigation Program 1',
duration: 10,
wateringPeriod: 2,
startTime: '12:00',
switches: [1, 2],
simultaneousIrrigation: true,
}
const mockIrrigationProgram2 = {
name: 'Irrigation Program 2',
duration: 20,
wateringPeriod: 4,
startTime: '05:00',
Expand Down Expand Up @@ -168,6 +173,7 @@ describe('IrrigationProgramsService', () => {
it('should find one irrigation program', async () => {
const id = uuidv4()
const mockPartialIrrigationProgram = {
name: 'Irrigation Program 1',
duration: 10,
wateringPeriod: 2,
startTime: '12:00',
Expand Down Expand Up @@ -222,6 +228,7 @@ describe('IrrigationProgramsService', () => {
const id = uuidv4()
const rev = '1-234'
const mockIrrigationProgram: IrrigationProgramEntity = {
name: 'Irrigation Program 1',
duration: 10,
wateringPeriod: 2,
startTime: '12:00',
Expand Down Expand Up @@ -296,6 +303,7 @@ describe('IrrigationProgramsService', () => {
const id = uuidv4()
const rev = '1-234'
const mockIrrigationProgram: IrrigationProgramEntity = {
name: 'Irrigation Program 1',
duration: 10,
wateringPeriod: 2,
startTime: '12:00',
Expand All @@ -321,6 +329,7 @@ describe('IrrigationProgramsService', () => {
const id = uuidv4()
const rev = '1-234'
const mockIrrigationProgram: IrrigationProgramEntity = {
name: 'Irrigation Program 1',
duration: 10,
wateringPeriod: 2,
startTime: '12:00',
Expand Down
1 change: 1 addition & 0 deletions src/irrigation-programs/irrigation-programs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type IrrigationProgramEntityWithId = IrrigationProgramEntity & IdentifiedDocumen
const irrigationEntityToIrrigationInterface = (
irrigationProgram: IrrigationProgramEntityWithId
): IrrigationProgram => ({
name: irrigationProgram.name,
id: irrigationProgram._id,
duration: irrigationProgram.duration,
wateringPeriod: irrigationProgram.wateringPeriod,
Expand Down

0 comments on commit bf5d2ff

Please sign in to comment.