Skip to content

Commit

Permalink
feat(unit test edit): unit test edit
Browse files Browse the repository at this point in the history
unit test edit
  • Loading branch information
septk committed May 5, 2019
1 parent a6a77c8 commit e41aaeb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
34 changes: 34 additions & 0 deletions test/devices.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as nock from 'nock'

import { API_CONFIG } from '../src/config/constants'
import { Devices } from '../src/modules/devices'

describe('Devices Test', () => {
it('should be a class', () => {
const devices = new Devices({} as any)
expect(devices instanceof Devices).toBeTruthy()
})

describe('getDeviceInfo() call', () => {
it('should return device obj', async () => {
nock(API_CONFIG.baseURL)
.get(`/devices/9E1F98`)
.reply(200)
const devices = new Devices({} as any)
const result = await devices.getDeviceInfo('9E1F98')
expect(result).toMatchSnapshot()
})

it('should return error', async () => {
const devices = new Devices({} as any)
try {
nock(API_CONFIG.baseURL)
.get(`/devices/9E1F98`)
.reply(404)
await devices.getDeviceInfo('9E1F98')
} catch (error) {
expect(error).toMatchSnapshot()
}
})
})
})
24 changes: 0 additions & 24 deletions test/sigfox-js.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as nock from 'nock'

import SigfoxApi from '../src/sigfox-js'
import { ConfigParams } from '../src/types/config-params'
import { API_CONFIG } from '../src/config/constants'

/**
* SigfoxApi test
Expand All @@ -19,27 +18,4 @@ describe('SigfoxApi test', () => {
expect(new SigfoxApi({} as ConfigParams)).toBeInstanceOf(SigfoxApi)
})
})

describe('getDeviceInfo() call', () => {
it('should return device obj', async () => {
nock(API_CONFIG.baseURL)
.get(`/devices/9E1F98`)
.reply(200)
const sigfox = new SigfoxApi({} as ConfigParams)
const result = await sigfox.getDeviceInfo('9E1F98')
expect(result).toMatchSnapshot()
})

it('should return error', async () => {
const sigfox = new SigfoxApi({} as ConfigParams)
try {
nock(API_CONFIG.baseURL)
.get(`/devices/9E1F98`)
.reply(404)
await sigfox.getDeviceInfo('9E1F98')
} catch (error) {
expect(error).toMatchSnapshot()
}
})
})
})

0 comments on commit e41aaeb

Please sign in to comment.