Skip to content

Commit

Permalink
test: add possible telegram responses as mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandenaardweg committed Dec 18, 2022
1 parent 13a44d0 commit 59f23f1
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 42 deletions.
223 changes: 183 additions & 40 deletions src/mocks/data/telegram.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,184 @@
// this has a backslash before the 2, wich errors out in the parser, so we comment it out
// ERROR: Legacy octal escape sequences cannot be used in template literals
// export const mockTelegramResponse = `/ISK5\2M550T-1012
export const mockTelegramResponse = `/ISK52M550T-1012
const v50l3 = `/ISK5\\2M550T-1012\r
\r
1-3:0.2.8(50)\r
0-0:1.0.0(221215222225W)\r
0-0:96.1.1(4530303434303037303138303138313137)\r
1-0:1.8.1(019037.267*kWh)\r
1-0:1.8.2(019495.788*kWh)\r
1-0:2.8.1(000000.002*kWh)\r
1-0:2.8.2(000000.007*kWh)\r
0-0:96.14.0(0002)\r
1-0:1.7.0(00.211*kW)\r
1-0:2.7.0(00.000*kW)\r
0-0:96.7.21(00007)\r
0-0:96.7.9(00004)\r
1-0:99.97.0(1)(0-0:96.7.19)(171130183027W)(0000000944*s)\r
1-0:32.32.0(00008)\r
1-0:52.32.0(00007)\r
1-0:72.32.0(00011)\r
1-0:32.36.0(00001)\r
1-0:52.36.0(00009)\r
1-0:72.36.0(00009)\r
0-0:96.13.0()\r
1-0:32.7.0(223.8*V)\r
1-0:52.7.0(222.6*V)\r
1-0:72.7.0(223.6*V)\r
1-0:31.7.0(000*A)\r
1-0:51.7.0(000*A)\r
1-0:71.7.0(000*A)\r
1-0:21.7.0(00.066*kW)\r
1-0:41.7.0(00.012*kW)\r
1-0:61.7.0(00.135*kW)\r
1-0:22.7.0(00.000*kW)\r
1-0:42.7.0(00.000*kW)\r
1-0:62.7.0(00.000*kW)\r
0-1:24.1.0(003)\r
0-1:96.1.0(4730303332353635353330393732333137)\r
0-1:24.2.1(221215222009W)(06770.798*m3)\r
!F736\r`;

1-3:0.2.8(50)
0-0:1.0.0(221215222225W)
0-0:96.1.1(4530303434303037303138303138313137)
1-0:1.8.1(019037.267*kWh)
1-0:1.8.2(019495.788*kWh)
1-0:2.8.1(000000.002*kWh)
1-0:2.8.2(000000.007*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(00.211*kW)
1-0:2.7.0(00.000*kW)
0-0:96.7.21(00007)
0-0:96.7.9(00004)
1-0:99.97.0(1)(0-0:96.7.19)(171130183027W)(0000000944*s)
1-0:32.32.0(00008)
1-0:52.32.0(00007)
1-0:72.32.0(00011)
1-0:32.36.0(00001)
1-0:52.36.0(00009)
1-0:72.36.0(00009)
0-0:96.13.0()
1-0:32.7.0(223.8*V)
1-0:52.7.0(222.6*V)
1-0:72.7.0(223.6*V)
1-0:31.7.0(000*A)
1-0:51.7.0(000*A)
1-0:71.7.0(000*A)
1-0:21.7.0(00.066*kW)
1-0:41.7.0(00.012*kW)
1-0:61.7.0(00.135*kW)
1-0:22.7.0(00.000*kW)
1-0:42.7.0(00.000*kW)
1-0:62.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303332353635353330393732333137)
0-1:24.2.1(221215222009W)(06770.798*m3)
!F736`;
const v50be = `FLU5\\253770234_A\r
\r
0-0:96.1.4(50215)\r
0-0:96.1.1(3153414731313030303736363136)\r
0-0:1.0.0(210320214636W)\r
1-0:1.8.1(001311.025*kWh)\r
1-0:1.8.2(001651.825*kWh)\r
1-0:2.8.1(001885.818*kWh)\r
1-0:2.8.2(000750.923*kWh)\r
0-0:96.14.0(0002)\r
1-0:1.7.0(00.433*kW)\r
1-0:2.7.0(00.000*kW)\r
1-0:21.7.0(00.438*kW)\r
1-0:22.7.0(00.000*kW)\r
1-0:32.7.0(240.9*V)\r
1-0:31.7.0(002.22*A)\r
0-0:96.3.10(1)\r
0-0:17.0.0(999.9*kW)\r
1-0:31.4.0(999*A)\r
0-0:96.13.0()\r
0-1:24.1.0(003)\r
0-1:96.1.1(37464C4F32313139303331393634)\r
0-1:24.4.0(1)\r
0-1:24.2.3(210320214626W)(02559.077*m3)\r
!85AF\r
`;

const v22 = `XMX5XMXABCE000063181\r
\r
0-0:96.1.1(31333634303033302020202020202020)\r
1-0:1.8.1(32586.251*kWh)\r
1-0:1.8.2(36388.384*kWh)\r
1-0:2.8.1(00000.111*kWh)\r
1-0:2.8.2(00000.286*kWh)\r
0-0:96.14.0(0001)\r
1-0:1.7.0(0005.01*kW)\r
1-0:2.7.0(0000.00*kW)\r
0-0:96.13.1()\r
0-0:96.13.0()\r
0-1:96.1.0(3238303131303038333133313637353133)\r
0-1:24.1.0(03)\r
0-1:24.3.0(180902110000)(08)(60)(1)(0-1:24.2.0)(m3)\r
(12007.760)\r
!\r
`;

const v42 = `KFM5KAIFA-METER\r
\r
1-3:0.2.8(42)\r
0-0:1.0.0(190228205019W)\r
0-0:96.1.1(4530303235303030303737373730303136)\r
1-0:1.8.1(005945.778*kWh)\r
1-0:1.8.2(004415.532*kWh)\r
1-0:2.8.1(000212.801*kWh)\r
1-0:2.8.2(000636.089*kWh)\r
0-0:96.14.0(0002)\r
1-0:1.7.0(02.992*kW)\r
1-0:2.7.0(00.000*kW)\r
0-0:96.7.21(00001)\r
0-0:96.7.9(00001)\r
1-0:99.97.0(2)(0-0:96.7.19)(180824143702S)(0000005600*s)(000101000001W)(2147483647*s)\r
1-0:32.32.0(00000)\r
1-0:32.36.0(00000)\r
0-0:96.13.1()\r
0-0:96.13.0()\r
1-0:31.7.0(012*A)\r
1-0:21.7.0(02.992*kW)\r
1-0:22.7.0(00.000*kW)\r
0-2:24.1.0(003)\r
0-2:96.1.0(4730303139333430333231323232383136)\r
0-2:24.2.1(190228200000W)(03514.244*m3)\r
!4983\r
`;

const v42l3 = `KFM5KAIFA-METER\r
\r
1-3:0.2.8(42)\r
0-0:1.0.0(220108000226W)\r
0-0:96.1.1(4530303236303030303330393835333136)\r
1-0:1.8.1(024575.366*kWh)\r
1-0:1.8.2(013445.403*kWh)\r
1-0:2.8.1(005595.177*kWh)\r
1-0:2.8.2(014397.615*kWh)\r
0-0:96.14.0(0001)\r
1-0:1.7.0(00.712*kW)\r
1-0:2.7.0(00.000*kW)\r
0-0:96.7.21(00003)\r
0-0:96.7.9(00001)\r
1-0:99.97.0(2)(0-0:96.7.19)(170326043804S)(0000011313*s)(000101000001W)(2147483647*s)\r
1-0:32.32.0(00000)\r
1-0:52.32.0(00001)\r
1-0:72.32.0(00001)\r
1-0:32.36.0(00000)\r
1-0:52.36.0(00000)\r
1-0:72.36.0(00000)\r
0-0:96.13.1()\r
0-0:96.13.0()\r
1-0:31.7.0(002*A)\r
1-0:51.7.0(000*A)\r
1-0:71.7.0(001*A)\r
1-0:21.7.0(00.400*kW)\r
1-0:41.7.0(00.127*kW)\r
1-0:61.7.0(00.194*kW)\r
1-0:22.7.0(00.000*kW)\r
1-0:42.7.0(00.000*kW)\r
1-0:62.7.0(00.000*kW)\r
!EF9E\r
`;

const v50 = `XMX5LGBBLA4415290514\r
\r
1-3:0.2.8(50)\r
0-0:1.0.0(180901194246S)\r
0-0:96.1.1(4530303435303034303134363938333137)\r
1-0:1.8.1(001362.372*kWh)\r
1-0:1.8.2(000851.129*kWh)\r
1-0:2.8.1(000000.000*kWh)\r
1-0:2.8.2(000000.000*kWh)\r
0-0:96.14.0(0001)\r
1-0:1.7.0(00.276*kW)\r
1-0:2.7.0(00.000*kW)\r
0-0:96.7.21(00002)\r
0-0:96.7.9(00000)\r
1-0:99.97.0(0)(0-0:96.7.19)\r
1-0:32.32.0(00002)\r
1-0:32.36.0(00000)\r
0-0:96.13.0()\r
1-0:32.7.0(230.0*V)\r
1-0:31.7.0(002*A)\r
1-0:21.7.0(00.276*kW)\r
1-0:22.7.0(00.000*kW)\r
0-1:24.1.0(003)\r
0-1:96.1.0(4730303339303031373637383534313137)\r
0-1:24.2.1(180901194004S)(00485.627*m3)\r
!22EE\r
`;

export const mockTelegramResponse = {
v50l3,
v50be,
v22,
v42,
v42l3,
v50,
};
4 changes: 2 additions & 2 deletions src/p1-meter-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ describe('HomeWizardEnergyApi', () => {
method: 'GET',
})
.reply(() => ({
data: mockTelegramResponse,
data: mockTelegramResponse['v50l3'],
statusCode: 200,
}));

const data = await p1MeterApi.getTelegram();

expect(data).toStrictEqual(mockTelegramResponse);
expect(data).toStrictEqual(mockTelegramResponse['v50l3']);
});

it('should throw an error on GET when the "telegram" endpoint returns a server error', async () => {
Expand Down

0 comments on commit 59f23f1

Please sign in to comment.