Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pinpong committed Sep 15, 2023
1 parent 18c2771 commit 97c0522
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/utils/stringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CLIENT_ERROR } from '../errors';
*/
export function valuesToStringList(values: ItemStatusResponse): string[] {
try {
return (values['sumstate']['value'] as string).slice(0, -1).split(';');
return values.sumstate.value.slice(0, -1).split(';');
} catch (e) {
throw new Error(CLIENT_ERROR.CANNOT_PARSE_STATUS);
}
Expand Down
23 changes: 16 additions & 7 deletions test/utils/stringUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ItemStatusResponse, SystemStatusResponse } from '../../src/client';
import { CLIENT_ERROR } from '../../src/errors';
import {
systemFilteredByGroup,
Expand All @@ -6,15 +7,23 @@ import {
} from '../../src/utils/stringUtils';

test('valuesToStringList', () => {
expect(valuesToStringList(JSON.parse('{"sumstate":{"value":"0;0;3;kW;10.001;"}}'), null)).toEqual(
['0', '0', '3', 'kW', '10.001']
);
expect(
valuesToStringList(JSON.parse('{"item0":{"sumstate":{"value":"0;0;3;C°;199.999;"}}}'), 'item0')
).toEqual(['0', '0', '3', 'C°', '199.999']);
expect(valuesToStringList(JSON.parse('{"sumstate":{"value":"0;0;3;kW;10.001;"}}'))).toEqual([
'0',
'0',
'3',
'kW',
'10.001',
]);
expect(valuesToStringList({ sumstate: { value: '0;0;3;C°;199.999;' } })).toEqual([
'0',
'0',
'3',
'C°',
'199.999',
]);

expect(() => {
valuesToStringList(JSON.parse('{"item0":{"sumstate":{"value":"0;0;0;0;0;"}}}'), 'item1');
valuesToStringList(JSON.parse('{}'));
}).toThrow(CLIENT_ERROR.CANNOT_PARSE_STATUS);
});

Expand Down

0 comments on commit 97c0522

Please sign in to comment.