From 961a030a727c011bc44da0bf7ce85eb070d8c353 Mon Sep 17 00:00:00 2001 From: marzavec Date: Fri, 29 Dec 2023 22:09:24 -0800 Subject: [PATCH] unit test update Back to 100% coverage --- package-lock.json | 18 +++++++++--------- test/addmod.test.js | 13 ++++++++----- test/join.test.js | 26 ++++++++++++++++++++++++++ test/removemod.test.js | 14 ++++++++++---- 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index ac0bc6b..f9b4c2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,18 @@ { "name": "hack.chat-v2", - "version": "2.2.0", + "version": "2.2.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "hack.chat-v2", - "version": "2.2.0", + "version": "2.2.1", "hasInstallScript": true, "license": "MIT", "dependencies": { "ascii-captcha": "^0.0.3", "enquirer": "^2.3.6", - "hackchat-server": "^2.2.27", + "hackchat-server": "^2.3.1", "http-server": "^14.1.0", "jsonwebtoken": "^9.0.2", "lowdb": "^3.0.0", @@ -2750,9 +2750,9 @@ } }, "node_modules/hackchat-server": { - "version": "2.2.27", - "resolved": "https://registry.npmjs.org/hackchat-server/-/hackchat-server-2.2.27.tgz", - "integrity": "sha512-ojTngxzBO9OYj12510XsoUEddMYbE3qf7AsRkyBfNStyiNKIMWG8/kyZkLsr/f/CIYKJZCQ3/Es6Cu6t/FBHvA==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/hackchat-server/-/hackchat-server-2.3.1.tgz", + "integrity": "sha512-q287JzAP3shM1pBq6ZG9BUza0bCuunz4R9hV5jgBEwAvJtp+t8P4ZNL8XpSnGe7Rcc9pkhg26uHMZ7TtUL5MYQ==", "dependencies": { "didyoumean2": "^4.2.0", "enquirer": "^2.3.6", @@ -8081,9 +8081,9 @@ "dev": true }, "hackchat-server": { - "version": "2.2.27", - "resolved": "https://registry.npmjs.org/hackchat-server/-/hackchat-server-2.2.27.tgz", - "integrity": "sha512-ojTngxzBO9OYj12510XsoUEddMYbE3qf7AsRkyBfNStyiNKIMWG8/kyZkLsr/f/CIYKJZCQ3/Es6Cu6t/FBHvA==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/hackchat-server/-/hackchat-server-2.3.1.tgz", + "integrity": "sha512-q287JzAP3shM1pBq6ZG9BUza0bCuunz4R9hV5jgBEwAvJtp+t8P4ZNL8XpSnGe7Rcc9pkhg26uHMZ7TtUL5MYQ==", "requires": { "didyoumean2": "^4.2.0", "enquirer": "^2.3.6", diff --git a/test/addmod.test.js b/test/addmod.test.js index fb32def..3b58bb1 100644 --- a/test/addmod.test.js +++ b/test/addmod.test.js @@ -38,8 +38,10 @@ describe('Checking addmod module', () => { // module main function it('should be invokable only by an admin', async () => { + const newCore = Object.assign({}, mocks.core); + const resp = await importedModule.run({ - core: mocks.core, + core: newCore, server: mocks.server, socket: mocks.plebSocket, payload: mockPayload, @@ -49,8 +51,10 @@ describe('Checking addmod module', () => { }); it('should add new trip to the config', async () => { + const newCore = Object.assign({}, mocks.core); + const resp = await importedModule.run({ - core: mocks.core, + core: newCore, server: mocks.server, socket: mocks.authedSocket, payload: mockPayload, @@ -60,18 +64,17 @@ describe('Checking addmod module', () => { }); it('should inform the new mod', async () => { + const newCore = Object.assign({}, mocks.core); mocks.server.findSockets = () => { return [{}]; } const resp = await importedModule.run({ - core: mocks.core, + core: newCore, server: mocks.server, socket: mocks.authedSocket, payload: mockPayload, }); - - mocks.core.appConfig.data.globalMods = []; expect(resp).to.be.true; }); diff --git a/test/join.test.js b/test/join.test.js index 6867d2d..ad7fafe 100644 --- a/test/join.test.js +++ b/test/join.test.js @@ -181,6 +181,32 @@ describe('Checking join module', () => { expect(resp).to.be.true; }); + it('should provide mod perks', async () => { + const newCore = Object.assign({}, mocks.core); + newCore.appConfig.data.globalMods = [ + { + trip: 'XVeP3T', + } + ]; + + const newSocket = Object.assign({}, mocks.authedSocket); + newSocket.channel = undefined; + newSocket.hcProtocol = undefined; + + const resp = await importedModule.run({ + core: newCore, + server: mocks.server, + socket: newSocket, + payload: { + cmd: 'join', + nick: 'admin#test', + channel: 'cake', + }, + }); + + expect(newSocket.ratelimitImmune).to.be.true; + }); + it('should announce new user', async () => { const newSocket = Object.assign({}, mocks.authedSocket); newSocket.channel = undefined; diff --git a/test/removemod.test.js b/test/removemod.test.js index 555199c..a84d1f6 100644 --- a/test/removemod.test.js +++ b/test/removemod.test.js @@ -6,7 +6,7 @@ let importedModule; const mockPayload = { cmd: 'removemod', - trip: 'newTrip', + trip: 'XVeP3T', } describe('Checking removemod module', () => { @@ -38,8 +38,10 @@ describe('Checking removemod module', () => { // module main function it('should be invokable only by an admin', async () => { + const newCore = Object.assign({}, mocks.core); + const resp = await importedModule.run({ - core: mocks.core, + core: newCore, server: mocks.server, socket: mocks.plebSocket, payload: mockPayload, @@ -49,8 +51,10 @@ describe('Checking removemod module', () => { }); it('should remove trip from the config', async () => { + const newCore = Object.assign({}, mocks.core); + const resp = await importedModule.run({ - core: mocks.core, + core: newCore, server: mocks.server, socket: mocks.authedSocket, payload: mockPayload, @@ -60,12 +64,14 @@ describe('Checking removemod module', () => { }); it('should inform the ex-mod', async () => { + const newCore = Object.assign({}, mocks.core); + mocks.server.findSockets = () => { return [{}]; } const resp = await importedModule.run({ - core: mocks.core, + core: newCore, server: mocks.server, socket: mocks.authedSocket, payload: mockPayload,