Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebilm committed Jul 7, 2024
1 parent a652ee3 commit 94df43e
Show file tree
Hide file tree
Showing 2 changed files with 447 additions and 5 deletions.
70 changes: 65 additions & 5 deletions test/unittests/myUplinkLogicSystemsWithDevices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,32 @@ describe('MyUplinkLogic: two systems with devices', () => {
country: 'MyCountry',
securityLevel: 'viewer',
hasAlarm: true,
devices: [{}, { id: 'ignoreWithoutName' }, { product: { name: 'Ignore without ID' } }, { id: 'Device1ID', product: { name: 'Product 1 Name' } }],
devices: [
{ wrong: 'data will be ignored' },
{ id: 'ignoreWithoutName' },
{ id: 'Device1ID', product: { name: 'Product 1 Name' } },
{ product: { name: 'Ignore without ID' } },
],
},
{
systemId: 'myOtherSystemID',
name: 'myOtherTestName',
country: 'Germany',
securityLevel: 'manager',
hasAlarm: false,
devices: [{ id: 'DeviceId2', product: { name: 'Product B', serialNumber: '123ABC' }, connectionState: 'Connected', currentFwVersion: '1.2.3' }],
devices: [
{ id: 'DeviceId2', product: { name: 'Product B', serialNumber: '123ABC' }, connectionState: 'Connected', currentFwVersion: '1.2.3' },
{},
{ id: 'Device3', product: { name: 'Product 3', serialNumber: 'ABCDEF' }, connectionState: 'Disconnected', currentFwVersion: '3.2.1' },
],
},
],
});
myUplinkRepositoryMock.expects('getActiveNotificationsAsync').withArgs('mySystemTestID', 'testtoken').resolves({});
myUplinkRepositoryMock.expects('getActiveNotificationsAsync').withArgs('myOtherSystemID', 'testtoken').resolves({});
myUplinkRepositoryMock.expects('getDevicePointsAsync').withArgs('Device1ID', 'testtoken').resolves(undefined);
myUplinkRepositoryMock.expects('getDevicePointsAsync').withArgs('DeviceId2', 'testtoken').resolves([]);
myUplinkRepositoryMock.expects('getDevicePointsAsync').withArgs('Device3', 'testtoken').resolves([]);

let error: string | undefined;
before(async () => {
Expand Down Expand Up @@ -65,7 +75,8 @@ describe('MyUplinkLogic: two systems with devices', () => {
it('should create devices', () => {
expect(dataTargetMock.CreateDeviceAsyncCalls).to.deep.include({ path: 'mySystemTestID.Device1ID', name: 'Product 1 Name' });
expect(dataTargetMock.CreateDeviceAsyncCalls).to.deep.include({ path: 'myOtherSystemID.DeviceId2', name: 'Product B' });
expect(dataTargetMock.CreateDeviceAsyncCalls).to.have.lengthOf(2);
expect(dataTargetMock.CreateDeviceAsyncCalls).to.deep.include({ path: 'myOtherSystemID.Device3', name: 'Product 3' });
expect(dataTargetMock.CreateDeviceAsyncCalls).to.have.lengthOf(3);
});

it('should create states', () => {
Expand Down Expand Up @@ -234,8 +245,51 @@ describe('MyUplinkLogic: two systems with devices', () => {
createObject: true,
role: 'info.firmware',
});
// Device 2-2:
expect(dataTargetMock.CreateStringStateAsyncCalls).to.deep.include({
path: 'myOtherSystemID.Device3.deviceId',
name: 'Device ID',
value: 'Device3',
createObject: true,
role: undefined,
});
expect(dataTargetMock.CreateStringStateAsyncCalls).to.deep.include({
path: 'myOtherSystemID.Device3.name',
name: 'Name',
value: 'Product 3',
createObject: true,
role: 'info.name',
});
expect(dataTargetMock.CreateStringStateAsyncCalls).to.deep.include({
path: 'myOtherSystemID.Device3.rawData',
name: 'Received raw JSON of parameter data',
value: '[]',
createObject: true,
role: undefined,
});
expect(dataTargetMock.CreateStringStateAsyncCalls).to.deep.include({
path: 'myOtherSystemID.Device3.serialNumber',
name: 'Serial Number',
value: 'ABCDEF',
createObject: true,
role: 'info.serial',
});
expect(dataTargetMock.CreateStringStateAsyncCalls).to.deep.include({
path: 'myOtherSystemID.Device3.connectionState',
name: 'Connection State',
value: 'Disconnected',
createObject: true,
role: 'info.status',
});
expect(dataTargetMock.CreateStringStateAsyncCalls).to.deep.include({
path: 'myOtherSystemID.Device3.currentFwVersion',
name: 'Current Firmware Version',
value: '3.2.1',
createObject: true,
role: 'info.firmware',
});

expect(dataTargetMock.CreateStringStateAsyncCalls).to.have.lengthOf(21);
expect(dataTargetMock.CreateStringStateAsyncCalls).to.have.lengthOf(27);
expect(dataTargetMock.CreateBooleanStateAsyncCalls).to.have.lengthOf(2);
});

Expand All @@ -252,7 +306,13 @@ describe('MyUplinkLogic: two systems with devices', () => {
role: 'json',
deviceId: 'DeviceId2',
});
expect(dataTargetMock.CreateWritableStringObjectAsyncCalls).to.have.lengthOf(2);
expect(dataTargetMock.CreateWritableStringObjectAsyncCalls).to.deep.include({
path: 'myOtherSystemID.Device3.setData',
name: 'Send raw JSON of parameter data',
role: 'json',
deviceId: 'Device3',
});
expect(dataTargetMock.CreateWritableStringObjectAsyncCalls).to.have.lengthOf(3);
});

it('should not do more', () => {
Expand Down
Loading

0 comments on commit 94df43e

Please sign in to comment.