From 9f432ab0e0ef41f2a937c0cd5e1a2a3ad849424f Mon Sep 17 00:00:00 2001 From: FantasticFiasco Date: Mon, 6 Jan 2025 12:44:28 +0100 Subject: [PATCH] wip --- .../axis-configuration/sample/parameters.ts | 4 +- .../src/parameters/Parameters.ts | 2 +- .../axis-configuration/test/DeviceMock.ts | 67 +++-- .../test/parameters/Parameters.test.ts | 270 ++++++++---------- .../test/user-accounts/User.test.ts | 12 +- .../axis-core/test/auth/challenge.test.ts | 2 +- packages/axis-core/test/auth/digest.test.ts | 2 +- .../test/Discovery.test.ts | 18 +- .../vendor/bonjour/test/bonjour.js | 2 +- .../vendor/multicast-dns/test.js | 2 +- .../test/Discovery.test.ts | 18 +- .../test/sockets/Message.test.ts | 14 +- .../axis-discovery/test/Discovery.test.ts | 18 +- .../test/caches/DeviceCache.test.ts | 2 +- .../FactoryDefaultResponse.test.ts | 12 +- .../test/restart/RestartResponse.test.ts | 6 +- 16 files changed, 224 insertions(+), 227 deletions(-) diff --git a/packages/axis-configuration/sample/parameters.ts b/packages/axis-configuration/sample/parameters.ts index bbac41f11..0a7f22257 100644 --- a/packages/axis-configuration/sample/parameters.ts +++ b/packages/axis-configuration/sample/parameters.ts @@ -40,8 +40,8 @@ const updateParameters = async (parameters: Parameters): Promise => { }; const print = (root: Map) => { - for (const parameter of Object.keys(root)) { - console.log(` ${parameter}=${root.get(parameter)}`); + for (const [name, value] of root.entries()) { + console.log(` ${name}=${value}`); } }; diff --git a/packages/axis-configuration/src/parameters/Parameters.ts b/packages/axis-configuration/src/parameters/Parameters.ts index f16f3f97e..e976b3742 100644 --- a/packages/axis-configuration/src/parameters/Parameters.ts +++ b/packages/axis-configuration/src/parameters/Parameters.ts @@ -45,7 +45,7 @@ export class Parameters { * @throws {UpdateParametersError} Updating one or many of the parameters failed. */ public async update(parameters: Map): Promise { - expect.toBeTrue(Object.keys(parameters).length > 0, 'At least one parameter must be specified'); + expect.toBeTrue(parameters.size > 0, 'At least one parameter must be specified'); const req = new UpdateParametersRequest(this.#connection, parameters); const res = await req.send(); diff --git a/packages/axis-configuration/test/DeviceMock.ts b/packages/axis-configuration/test/DeviceMock.ts index 59c1dc7b0..020fd537a 100644 --- a/packages/axis-configuration/test/DeviceMock.ts +++ b/packages/axis-configuration/test/DeviceMock.ts @@ -4,15 +4,20 @@ import * as passport from 'passport'; import { DigestStrategy } from 'passport-http'; export class DeviceMock { - private server?: Server; - private address?: string; - private port?: number; + #server?: Server; + #address?: string; + #port?: number; + + readonly #parameters = new Map([ + ['Network.Bonjour.FriendlyName', 'Main Entrance'], + ['Network.Bonjour.Enabled', 'yes'], + ]); readonly username = 'some-user'; readonly password = 'some-password'; get uri(): string { - return `http://${this.address}:${this.port}`; + return `http://${this.#address}:${this.#port}`; } listen(address: string, port: number): Promise { @@ -39,9 +44,9 @@ export class DeviceMock { app.get('/axis-cgi/pwdgrp.cgi', passport.authenticate('digest', { session: false }), this.#pwdgrpHandler); return new Promise((resolve) => { - this.server = app.listen(port, address, () => { - this.address = (this.server?.address() as AddressInfo).address; - this.port = (this.server?.address() as AddressInfo).port; + this.#server = app.listen(port, address, () => { + this.#address = (this.#server?.address() as AddressInfo).address; + this.#port = (this.#server?.address() as AddressInfo).port; resolve(); }); @@ -50,10 +55,10 @@ export class DeviceMock { close(): Promise { return new Promise((resolve, reject) => { - if (!this.server) { + if (!this.#server) { reject('Express server is not defined'); } else { - this.server.close((err) => { + this.#server.close((err) => { if (err) { reject(err); } else { @@ -70,6 +75,10 @@ export class DeviceMock { this.#listParameters(req, res); break; + case 'update': + this.#updateParameters(req, res); + break; + default: res.status(400).send(); } @@ -79,25 +88,39 @@ export class DeviceMock { const responseLines: string[] = []; const group = req.query.group as string; - const parameters = group.split(','); - - for (const parameter of parameters) { - switch (parameter) { - case 'Network.Bonjour.FriendlyName': - responseLines.push('Network.Bonjour.FriendlyName=Main Entrance'); - break; - case 'Network.Bonjour.Enabled': - responseLines.push('Network.Bonjour.Enabled=yes'); - break; - default: - responseLines.push(`# Error: Error -1 getting param in group '${parameter}'`); - break; + const names = group.split(','); + + for (const name of names) { + const value = this.#parameters.get(name); + + if (value) { + responseLines.push(`${name}=${value}`); + } else { + responseLines.push(`# Error: Error -1 getting param in group '${name}'`); } } res.send(responseLines.join('\r\n')); }; + #updateParameters = (req: express.Request, res: express.Response) => { + const responseLines: string[] = []; + + for (const [name, value] of Object.entries(req.query)) { + if (name === 'action') { + continue; + } + + if (this.#parameters.has(name)) { + this.#parameters.set(name, value as string); + } else { + responseLines.push(`# Error: Error setting '${name}' to '${value}'!\r\n`); + } + } + + res.send(responseLines.length === 0 ? 'OK' : responseLines.join('\r\n')); + }; + #pwdgrpHandler = (_: express.Request, res: express.Response) => { res.send('Success'); }; diff --git a/packages/axis-configuration/test/parameters/Parameters.test.ts b/packages/axis-configuration/test/parameters/Parameters.test.ts index b44d7a80a..f23a939be 100644 --- a/packages/axis-configuration/test/parameters/Parameters.test.ts +++ b/packages/axis-configuration/test/parameters/Parameters.test.ts @@ -1,6 +1,6 @@ import { ExpectationError } from '@fantasticfiasco/expect'; import { Connection, Protocol } from 'axis-core'; -import { Parameters } from '../../src'; +import { Parameters, UpdateParametersError } from '../../src'; import { DeviceMock } from '../DeviceMock'; var device: DeviceMock; @@ -57,10 +57,8 @@ describe('#get', () => { const connection = createConnection(); const parameters = new Parameters(connection); - const name = 'Unknown.Parameter'; - // Act - const got = await parameters.get(name); + const got = await parameters.get('Unknown.Parameter'); // Assert const want = new Map(); @@ -72,11 +70,8 @@ describe('#get', () => { const connection = createConnection(); const parameters = new Parameters(connection); - const name1 = 'Unknown.Parameter1'; - const name2 = 'Unknown.Parameter2'; - // Act - const got = await parameters.get(name1, name2); + const got = await parameters.get('Unknown.Parameter1', 'Unknown.Parameter2'); // Assert const want = new Map(); @@ -109,7 +104,7 @@ describe('#get', () => { const fn = () => parameters.get(); // Assert - await expect(fn).rejects.toBeInstanceOf(ExpectationError); + await expect(fn()).rejects.toBeInstanceOf(ExpectationError); }); // test('should throw exception if device is unresponsive', async () => { @@ -136,148 +131,127 @@ describe('#get', () => { const fn = () => parameters.get('Network.Bonjour.FriendlyName'); // Assert - await expect(fn).rejects.toBeInstanceOf(Error); + await expect(fn()).rejects.toBeInstanceOf(Error); }); }); -// describe('#update', () => { -// const connection = createConnection(); -// const parameters = new Parameters(connection); - -// test('should update single parameter', async () => { -// // Arrange -// // const scope = nock(connection.url) -// // .get(/param.cgi\?action=update/) -// // .reply(200, 'OK'); - -// // Act -// await parameters.update({ 'Network.Bonjour.FriendlyName': 'Main Entrance' }); - -// // Assert -// // expect(scope.isDone()).toBe(true); -// }); - -// test('should update multiple parameters', async () => { -// // Arrange -// // const scope = nock(connection.url) -// // .get(/param.cgi\?action=update/) -// // .reply(200, 'OK'); - -// // Act -// await parameters.update({ -// 'Network.Bonjour.FriendlyName': 'Main Entrance', -// 'Network.Bonjour.Enabled': 'yes', -// }); - -// // Assert -// // expect(scope.isDone()).toBe(true); -// }); - -// test('should not update single unknown parameter', async () => { -// // Arrange -// const name = 'Unknown.Parameter'; -// const value = 'Value'; - -// // nock(connection.url) -// // .get(/param.cgi\?action=update/) -// // .reply(200, `# Error: Error setting '${name}' to '${value}'!\r\n`); - -// try { -// // Act -// await parameters.update({ [name]: value }); -// throw new Error('This exception should not be thrown'); -// } catch (error) { -// // Assert -// expect(error).toBeInstanceOf(UpdateParametersError); -// expect((error as UpdateParametersError).parameterNames).toEqual([name]); -// } -// }); - -// test('should not update multiple unknown parameters', async () => { -// // Arrange -// const name1 = 'Unknown.Parameter1'; -// const value1 = 'Value1'; -// const name2 = 'Unknown.Parameter2'; -// const value2 = 'Value2'; - -// // nock(connection.url) -// // .get(/param.cgi\?action=update/) -// // .reply(200, `# Error: Error setting '${name1}' to '${value1}'!\r\n# Error: Error setting '${name2}' to '${value2}'!\r\n`); - -// try { -// // Act -// await parameters.update({ [name1]: value1, [name2]: value2 }); -// throw new Error('This exception should not be thrown'); -// } catch (error) { -// // Assert -// expect(error).toBeInstanceOf(UpdateParametersError); -// expect((error as UpdateParametersError).parameterNames).toEqual([name1, name2]); -// } -// }); - -// test('should update a mixture of known and unknown parameters', async () => { -// // Arrange -// const name = 'Unknown.Parameter'; -// const value = 'Value'; - -// // nock(connection.url) -// // .get(/param.cgi\?action=update/) -// // .reply(200, `# Error: Error setting '${name}' to '${value}'!\r\n`); - -// try { -// // Act -// await parameters.update({ 'Network.Bonjour.FriendlyName': 'Main Entrance', name: value }); -// throw new Error('This exception should not be thrown'); -// } catch (error) { -// // Assert -// expect(error).toBeInstanceOf(UpdateParametersError); -// expect((error as UpdateParametersError).parameterNames).toEqual([name]); -// } -// }); - -// test('should throw exception if no parameters are specified', async () => { -// try { -// // Act -// await parameters.update({}); -// throw new Error('This exception should not be thrown'); -// } catch (error) { -// // Assert -// expect(error).toBeInstanceOf(ExpectationError); -// } -// }); - -// test('should throw exception if device is unresponsive', async () => { -// // Arrange -// // nock(connection.url) -// // .get(/param.cgi\?action=update/) -// // .replyWithError(`Error: connect ETIMEDOUT ${connection.address}:${connection.port}`); - -// try { -// // Act -// await parameters.update({ 'Network.Bonjour.FriendlyName': 'Main Entrance' }); -// throw new Error('This exception should not be thrown'); -// } catch (error) { -// // Assert -// expect(error).toBeInstanceOf(Error); -// } -// }); - -// test('should throw exception if user is unauthorized', async () => { -// // Arrange -// // nock(connection.url) -// // .get(/param.cgi\?action=update/) -// // .reply(401); - -// try { -// // Act -// await parameters.update({ 'Network.Bonjour.FriendlyName': 'Main Entrance' }); -// throw new Error('This exception should not be thrown'); -// } catch (error) { -// // Assert -// expect(error).toBeInstanceOf(Error); -// } -// }); -// }); +describe('#update', () => { + test('should update single parameter', async () => { + // Arrange + const connection = createConnection(); + const parameters = new Parameters(connection); + + // Act + await parameters.update(new Map([['Network.Bonjour.FriendlyName', 'Main Entrance']])); + }); + + test('should update multiple parameters', async () => { + // Arrange + const connection = createConnection(); + const parameters = new Parameters(connection); + + // Act + await parameters.update( + new Map([ + ['Network.Bonjour.FriendlyName', 'Main Entrance'], + ['Network.Bonjour.Enabled', 'yes'], + ]), + ); + }); + + test('should not update single unknown parameter', async () => { + // Arrange + const connection = createConnection(); + const parameters = new Parameters(connection); + + const name = 'Unknown.Parameter'; + + const fn = () => parameters.update(new Map([[name, 'Value']])); + + // Assert + await expect(fn()).rejects.toStrictEqual(new UpdateParametersError([name])); + }); + + test('should not update multiple unknown parameters', async () => { + // Arrange + const connection = createConnection(); + const parameters = new Parameters(connection); + + const name1 = 'Unknown.Parameter1'; + const name2 = 'Unknown.Parameter2'; + + // Act + const fn = () => + parameters.update( + new Map([ + [name1, 'Value1'], + [name2, 'Value2'], + ]), + ); + + // Assert + await expect(fn()).rejects.toStrictEqual(new UpdateParametersError([name1, name2])); + }); + + test('should update a mixture of known and unknown parameters', async () => { + // Arrange + const connection = createConnection(); + const parameters = new Parameters(connection); + + const name = 'Unknown.Parameter'; + + // Act + const fn = () => + parameters.update( + new Map([ + ['Network.Bonjour.FriendlyName', 'Main Entrance'], + [name, 'Value'], + ]), + ); + + // Assert + await expect(fn()).rejects.toStrictEqual(new UpdateParametersError([name])); + }); + + test('should throw exception if no parameters are specified', async () => { + // Arrange + const connection = createConnection(); + const parameters = new Parameters(connection); + + // Act + const fn = () => parameters.update(new Map()); + + // Assert + await expect(fn()).rejects.toBeInstanceOf(ExpectationError); + }); + + // test('should throw exception if device is unresponsive', async () => { + // // Arrange + // // nock(connection.url) + // // .get(/param.cgi\?action=update/) + // // .replyWithError(`Error: connect ETIMEDOUT ${connection.address}:${connection.port}`); + + // try { + // // Act + // await parameters.update({ 'Network.Bonjour.FriendlyName': 'Main Entrance' }); + // throw new Error('This exception should not be thrown'); + // } catch (error) { + // // Assert + // expect(error).toBeInstanceOf(Error); + // } + // }); + + test('should throw exception if user is unauthorized', async () => { + // Arrange + const connection = createConnection('wrong-password'); + const parameters = new Parameters(connection); + + const fn = () => parameters.update(new Map([['Network.Bonjour.FriendlyName', 'Main Entrance']])); + + // Arrange + await expect(fn()).rejects.toBeInstanceOf(Error); + }); +}); const createConnection = (password: string | undefined = undefined): Connection => { const { protocol, hostname, port } = new URL(device.uri); diff --git a/packages/axis-configuration/test/user-accounts/User.test.ts b/packages/axis-configuration/test/user-accounts/User.test.ts index ad5508b70..96ab98db0 100644 --- a/packages/axis-configuration/test/user-accounts/User.test.ts +++ b/packages/axis-configuration/test/user-accounts/User.test.ts @@ -9,7 +9,7 @@ describe('users', () => { const fn = () => new User(Generate.string(0), 'secret', AccessRights.Viewer, false); // Assert - expect(fn).toThrowError(ExpectationError); + expect(fn()).toThrow(ExpectationError); }); test('should throw exception if to long', () => { @@ -17,7 +17,7 @@ describe('users', () => { const fn = () => new User(Generate.string(15), 'secret', AccessRights.Viewer, false); // Assert - expect(fn).toThrowError(ExpectationError); + expect(fn()).toThrow(ExpectationError); }); test('should throw exception if containing unsupported characters', () => { @@ -25,7 +25,7 @@ describe('users', () => { const fn = () => new User('Joe-', 'secret', AccessRights.Viewer, false); // Assert - expect(fn).toThrowError(ExpectationError); + expect(fn()).toThrow(ExpectationError); }); }); @@ -35,7 +35,7 @@ describe('users', () => { const fn = () => new User('Joe', Generate.string(0), AccessRights.Viewer, false); // Assert - expect(fn).toThrowError(ExpectationError); + expect(fn()).toThrow(ExpectationError); }); test('should throw exception if to long', () => { @@ -43,7 +43,7 @@ describe('users', () => { const fn = () => new User('Joe', Generate.string(65), AccessRights.Viewer, false); // Assert - expect(fn).toThrowError(ExpectationError); + expect(fn()).toThrow(ExpectationError); }); test('should throw exception if containing unsupported characters', () => { @@ -51,7 +51,7 @@ describe('users', () => { const fn = () => new User('Joe', `secret-${String.fromCharCode(31)}`, AccessRights.Viewer, false); // Assert - expect(fn).toThrowError(ExpectationError); + expect(fn()).toThrow(ExpectationError); }); }); }); diff --git a/packages/axis-core/test/auth/challenge.test.ts b/packages/axis-core/test/auth/challenge.test.ts index eb23d8bd0..3de4b4719 100644 --- a/packages/axis-core/test/auth/challenge.test.ts +++ b/packages/axis-core/test/auth/challenge.test.ts @@ -52,6 +52,6 @@ describe('#parse should', () => { const fn = () => parse('Invalid realm="test"'); // Assert - expect(fn).toThrow(); + expect(fn()).toThrow(); }); }); diff --git a/packages/axis-core/test/auth/digest.test.ts b/packages/axis-core/test/auth/digest.test.ts index 639d9766d..8e30d6e16 100644 --- a/packages/axis-core/test/auth/digest.test.ts +++ b/packages/axis-core/test/auth/digest.test.ts @@ -102,7 +102,7 @@ describe('#createHeader should', () => { const fn = () => createHeader('GET', '/some/path/', 'root', 'pass', challenge); // Assert - expect(fn).toThrow(); + expect(fn()).toThrow(); }); }); diff --git a/packages/axis-discovery-bonjour/test/Discovery.test.ts b/packages/axis-discovery-bonjour/test/Discovery.test.ts index d284fa4ca..b10d7113f 100644 --- a/packages/axis-discovery-bonjour/test/Discovery.test.ts +++ b/packages/axis-discovery-bonjour/test/Discovery.test.ts @@ -7,7 +7,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.addListener('hello', fn); + const self = discovery.addListener('hello', fn()); discovery.emit('hello', mockedDevice()); // Assert @@ -21,7 +21,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.on('hello', fn); + const self = discovery.on('hello', fn()); discovery.emit('hello', mockedDevice()); // Assert @@ -35,7 +35,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.once('hello', fn); + const self = discovery.once('hello', fn()); discovery.emit('hello', mockedDevice()); discovery.emit('hello', mockedDevice()); @@ -50,7 +50,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.addListener('hello', fn).removeListener('hello', fn); + const self = discovery.addListener('hello', fn()).removeListener('hello', fn()); discovery.emit('hello', mockedDevice()); // Assert @@ -64,7 +64,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.on('hello', fn).off('hello', fn); + const self = discovery.on('hello', fn()).off('hello', fn()); discovery.emit('hello', mockedDevice()); // Assert @@ -78,7 +78,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.on('hello', fn).removeAllListeners('hello'); + const self = discovery.on('hello', fn()).removeAllListeners('hello'); discovery.emit('hello', mockedDevice()); // Assert @@ -107,7 +107,7 @@ describe('Discovery', () => { const expected = 2; // Act - const got = discovery.on('hello', fn).on('hello', fn).listenerCount('hello'); + const got = discovery.on('hello', fn()).on('hello', fn()).listenerCount('hello'); // Assert expect(got).toBe(expected); @@ -171,7 +171,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const got = discovery.on('hello', fn).eventNames(); + const got = discovery.on('hello', fn()).eventNames(); // Assert expect([...got]).toStrictEqual(['hello']); @@ -183,7 +183,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const got = discovery.on('hello', fn).on('goodbye', fn).eventNames(); + const got = discovery.on('hello', fn()).on('goodbye', fn()).eventNames(); // Assert expect([...got]).toStrictEqual(['hello', 'goodbye']); diff --git a/packages/axis-discovery-bonjour/vendor/bonjour/test/bonjour.js b/packages/axis-discovery-bonjour/vendor/bonjour/test/bonjour.js index 1b87080a1..d2746e5bb 100644 --- a/packages/axis-discovery-bonjour/vendor/bonjour/test/bonjour.js +++ b/packages/axis-discovery-bonjour/vendor/bonjour/test/bonjour.js @@ -32,7 +32,7 @@ var port = function (cb) { }) } -var test = function (name, fn) { +var test = function (name, fn()) { tape(name, function (t) { port(function (p) { fn(Bonjour({ ip: '127.0.0.1', port: p, multicast: false }), t) diff --git a/packages/axis-discovery-bonjour/vendor/multicast-dns/test.js b/packages/axis-discovery-bonjour/vendor/multicast-dns/test.js index c51cd7798..7445da9a7 100644 --- a/packages/axis-discovery-bonjour/vendor/multicast-dns/test.js +++ b/packages/axis-discovery-bonjour/vendor/multicast-dns/test.js @@ -13,7 +13,7 @@ var port = function (cb) { }) } -var test = function (name, fn) { +var test = function (name, fn()) { tape(name, function (t) { port(function (p) { var dns = mdns({ip: '127.0.0.1', port: p, multicast: false}) diff --git a/packages/axis-discovery-ssdp/test/Discovery.test.ts b/packages/axis-discovery-ssdp/test/Discovery.test.ts index 2c5a5e5ee..41b8d6afb 100644 --- a/packages/axis-discovery-ssdp/test/Discovery.test.ts +++ b/packages/axis-discovery-ssdp/test/Discovery.test.ts @@ -64,7 +64,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.addListener('hello', fn); + const self = discovery.addListener('hello', fn()); discovery.emit('hello', mockedDevice()); // Assert @@ -78,7 +78,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.on('hello', fn); + const self = discovery.on('hello', fn()); discovery.emit('hello', mockedDevice()); // Assert @@ -92,7 +92,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.once('hello', fn); + const self = discovery.once('hello', fn()); discovery.emit('hello', mockedDevice()); discovery.emit('hello', mockedDevice()); @@ -107,7 +107,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.addListener('hello', fn).removeListener('hello', fn); + const self = discovery.addListener('hello', fn()).removeListener('hello', fn()); discovery.emit('hello', mockedDevice()); // Assert @@ -121,7 +121,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.on('hello', fn).off('hello', fn); + const self = discovery.on('hello', fn()).off('hello', fn()); discovery.emit('hello', mockedDevice()); // Assert @@ -135,7 +135,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.on('hello', fn).removeAllListeners('hello'); + const self = discovery.on('hello', fn()).removeAllListeners('hello'); discovery.emit('hello', mockedDevice()); // Assert @@ -164,7 +164,7 @@ describe('Discovery', () => { const expected = 2; // Act - const got = discovery.on('hello', fn).on('hello', fn).listenerCount('hello'); + const got = discovery.on('hello', fn()).on('hello', fn()).listenerCount('hello'); // Assert expect(got).toBe(expected); @@ -229,7 +229,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const got = discovery.on('hello', fn).eventNames(); + const got = discovery.on('hello', fn()).eventNames(); // Assert expect([...got]).toStrictEqual(['hello']); @@ -241,7 +241,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const got = discovery.on('hello', fn).on('goodbye', fn).eventNames(); + const got = discovery.on('hello', fn()).on('goodbye', fn()).eventNames(); // Assert expect([...got]).toStrictEqual(['hello', 'goodbye']); diff --git a/packages/axis-discovery-ssdp/test/sockets/Message.test.ts b/packages/axis-discovery-ssdp/test/sockets/Message.test.ts index 30c05837e..3383f71d6 100644 --- a/packages/axis-discovery-ssdp/test/sockets/Message.test.ts +++ b/packages/axis-discovery-ssdp/test/sockets/Message.test.ts @@ -14,7 +14,7 @@ describe('Message', () => { // Act const got = new Message( '192.168.1.100', - Buffer.from('HTTP/1.1 200 OK\r\n' + ' USN: uuid:Upnp-BasicDevice-1_0-ACCC8E270AD8::urn:axis-com:service:BasicService:1 \r\n') + Buffer.from('HTTP/1.1 200 OK\r\n' + ' USN: uuid:Upnp-BasicDevice-1_0-ACCC8E270AD8::urn:axis-com:service:BasicService:1 \r\n'), ); // Assert @@ -51,7 +51,7 @@ describe('Message', () => { const got = new Message('192.168.1.100', Buffer.from('HTTP/1.1 200 OK\r\n')); // Assert - expect(() => got.location).toThrowError(); + expect(() => got.location).toThrow(); }); test('#usn should fail if missing', () => { @@ -59,7 +59,7 @@ describe('Message', () => { const got = new Message('192.168.1.100', Buffer.from('HTTP/1.1 200 OK\r\n')); // Assert - expect(() => got.usn).toThrowError(); + expect(() => got.usn).toThrow(); }); }); @@ -85,7 +85,7 @@ describe('Message', () => { const got = new Message('192.168.1.100', Buffer.from('HTTP/1.1 200 OK\r\n')); // Assert - expect(() => got.location).toThrowError(); + expect(() => got.location).toThrow(); }); test('#usn', () => { @@ -101,7 +101,7 @@ describe('Message', () => { const got = new Message('192.168.1.100', Buffer.from('HTTP/1.1 200 OK\r\n')); // Assert - expect(() => got.usn).toThrowError(); + expect(() => got.usn).toThrow(); }); test('#nt', () => { @@ -117,7 +117,7 @@ describe('Message', () => { const got = new Message('192.168.1.100', Buffer.from('HTTP/1.1 200 OK\r\n')); // Assert - expect(() => got.nt).toThrowError(); + expect(() => got.nt).toThrow(); }); test('#nts', () => { @@ -133,7 +133,7 @@ describe('Message', () => { const got = new Message('192.168.1.100', Buffer.from('HTTP/1.1 200 OK\r\n')); // Assert - expect(() => got.nts).toThrowError(); + expect(() => got.nts).toThrow(); }); }); }); diff --git a/packages/axis-discovery/test/Discovery.test.ts b/packages/axis-discovery/test/Discovery.test.ts index 1e8efe8c1..8754b8a4d 100644 --- a/packages/axis-discovery/test/Discovery.test.ts +++ b/packages/axis-discovery/test/Discovery.test.ts @@ -7,7 +7,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.addListener('hello', fn); + const self = discovery.addListener('hello', fn()); discovery.emit('hello', mockedDevice()); // Assert @@ -21,7 +21,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.on('hello', fn); + const self = discovery.on('hello', fn()); discovery.emit('hello', mockedDevice()); // Assert @@ -35,7 +35,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.once('hello', fn); + const self = discovery.once('hello', fn()); discovery.emit('hello', mockedDevice()); discovery.emit('hello', mockedDevice()); @@ -50,7 +50,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.addListener('hello', fn).removeListener('hello', fn); + const self = discovery.addListener('hello', fn()).removeListener('hello', fn()); discovery.emit('hello', mockedDevice()); // Assert @@ -64,7 +64,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.on('hello', fn).off('hello', fn); + const self = discovery.on('hello', fn()).off('hello', fn()); discovery.emit('hello', mockedDevice()); // Assert @@ -78,7 +78,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const self = discovery.on('hello', fn).removeAllListeners('hello'); + const self = discovery.on('hello', fn()).removeAllListeners('hello'); discovery.emit('hello', mockedDevice()); // Assert @@ -107,7 +107,7 @@ describe('Discovery', () => { const expected = 2; // Act - const got = discovery.on('hello', fn).on('hello', fn).listenerCount('hello'); + const got = discovery.on('hello', fn()).on('hello', fn()).listenerCount('hello'); // Assert expect(got).toBe(expected); @@ -171,7 +171,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const got = discovery.on('hello', fn).eventNames(); + const got = discovery.on('hello', fn()).eventNames(); // Assert expect([...got]).toStrictEqual(['hello']); @@ -183,7 +183,7 @@ describe('Discovery', () => { const fn = jest.fn(); // Act - const got = discovery.on('hello', fn).on('goodbye', fn).eventNames(); + const got = discovery.on('hello', fn()).on('goodbye', fn()).eventNames(); // Assert expect([...got]).toStrictEqual(['hello', 'goodbye']); diff --git a/packages/axis-discovery/test/caches/DeviceCache.test.ts b/packages/axis-discovery/test/caches/DeviceCache.test.ts index a4ac13737..1b8c05b4c 100644 --- a/packages/axis-discovery/test/caches/DeviceCache.test.ts +++ b/packages/axis-discovery/test/caches/DeviceCache.test.ts @@ -55,7 +55,7 @@ describe('DeviceCache', () => { const fn = () => subject.update(DEVICE_WITHOUT_MAC_ADDRESS); // Assert - expect(fn).toThrowError(); + expect(fn()).toThrow(); }); }); }); diff --git a/packages/axis-maintenance/test/factory-default/FactoryDefaultResponse.test.ts b/packages/axis-maintenance/test/factory-default/FactoryDefaultResponse.test.ts index 239245858..0be5362cf 100644 --- a/packages/axis-maintenance/test/factory-default/FactoryDefaultResponse.test.ts +++ b/packages/axis-maintenance/test/factory-default/FactoryDefaultResponse.test.ts @@ -19,7 +19,7 @@ describe('factory default response', () => { const fn = () => response.assertSuccess(); // Assert - expect(fn).not.toThrowError(); + expect(fn()).not.toThrow(); }); test('should throw exception given error response without body', () => { @@ -37,7 +37,7 @@ describe('factory default response', () => { const fn = () => response.assertSuccess(); // Assert - expect(fn).toThrowError(Error); + expect(fn()).toThrow(Error); }); test('should throw exception given error response with body', () => { @@ -56,7 +56,7 @@ describe('factory default response', () => { const fn = () => response.assertSuccess(); // Assert - expect(fn).toThrowError(Error); + expect(fn()).toThrow(Error); }); }); @@ -77,7 +77,7 @@ describe('factory default response', () => { const fn = () => response.assertSuccess(); // Assert - expect(fn).not.toThrowError(); + expect(fn()).not.toThrow(); }); test('should throw exception given error response without body', () => { @@ -95,7 +95,7 @@ describe('factory default response', () => { const fn = () => response.assertSuccess(); // Assert - expect(fn).toThrowError(Error); + expect(fn()).toThrow(Error); }); test('should throw exception given error response with body', () => { @@ -114,7 +114,7 @@ describe('factory default response', () => { const fn = () => res.assertSuccess(); // Assert - expect(fn).toThrowError(Error); + expect(fn()).toThrow(Error); }); }); }); diff --git a/packages/axis-maintenance/test/restart/RestartResponse.test.ts b/packages/axis-maintenance/test/restart/RestartResponse.test.ts index 979994849..5a5756128 100644 --- a/packages/axis-maintenance/test/restart/RestartResponse.test.ts +++ b/packages/axis-maintenance/test/restart/RestartResponse.test.ts @@ -18,7 +18,7 @@ describe('restart response', () => { const fn = () => res.assertSuccess(); // Assert - expect(fn).not.toThrowError(); + expect(fn()).not.toThrow(); }); test('should throw exception given error response without body', () => { @@ -36,7 +36,7 @@ describe('restart response', () => { const fn = () => res.assertSuccess(); // Assert - expect(fn).toThrowError(Error); + expect(fn()).toThrow(Error); }); test('should throw exception given error response with body', () => { @@ -55,7 +55,7 @@ describe('restart response', () => { const fn = () => res.assertSuccess(); // Assert - expect(fn).toThrowError(Error); + expect(fn()).toThrow(Error); }); }); });