diff --git a/test/devices.test.ts b/test/devices.test.ts new file mode 100644 index 0000000..739e2e2 --- /dev/null +++ b/test/devices.test.ts @@ -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() + } + }) + }) +}) diff --git a/test/sigfox-js.test.ts b/test/sigfox-js.test.ts index 99fc3b6..1a6d920 100644 --- a/test/sigfox-js.test.ts +++ b/test/sigfox-js.test.ts @@ -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 @@ -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() - } - }) - }) })