Skip to content

Commit

Permalink
Added more tests for Maker API service
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewpetro committed Mar 3, 2024
1 parent 2b27274 commit f7755a5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/maker-api/maker-api.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing'
import { MakerApiService } from './maker-api.service'
import { ConfigModule } from '@nestjs/config'
import { DeviceState } from '@/enums/device-state.interface'
import mockData from './mocks/maker-api.mocks.json'
import axios from 'axios'

Expand Down Expand Up @@ -48,4 +49,16 @@ describe('MakerApiService', () => {
const deviceDetails = await service.getAllDeviceDetails()
expect(deviceDetails).toEqual({})
})

it('should set a device state correctly', async () => {
await service.setDeviceState(42, DeviceState.ON)
expect(mockGet).toHaveBeenCalledWith(`/42/${DeviceState.ON}`)
})

it('should get a device state correctly', async () => {
mockGet.mockResolvedValue({ data: { value: DeviceState.ON } })
const deviceState = await service.getDeviceState(42)
expect(mockGet).toHaveBeenCalledWith(`/42/attribute/switch`)
expect(deviceState).toEqual(DeviceState.ON)
})
})

0 comments on commit f7755a5

Please sign in to comment.