Skip to content

Commit

Permalink
v1.2.0 - Add Unit Tests (#4)
Browse files Browse the repository at this point in the history
* Add util tests

Minor QOL improvement in link wallet where the sign-in link is also sent to the user so they can click on it instead of having to scan the QR code.
  • Loading branch information
jacobpretorius authored Feb 27, 2023
1 parent 82bbe5b commit 0d6f21e
Show file tree
Hide file tree
Showing 80 changed files with 1,956 additions and 329 deletions.
1 change: 1 addition & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ jobs:
cache: 'npm'
- run: npm ci
- run: npm run build
- run: npm run test
29 changes: 29 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests.v2",
"request": "launch",
"args": [
"--runInBand",
"--watchAll=false",
"--testNamePattern",
"${jest.testNamePattern}",
"--runTestsByPath",
"${jest.testFile}"
],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"program": "${workspaceFolder}/node_modules/.bin/jest",
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
}
]
}
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ module.exports = {
'^.+\\.(ts|tsx)?$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest',
},
modulePathIgnorePatterns: ['<rootDir>/dist/'],
};
28 changes: 24 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "XRPL-Discord-Bot",
"version": "1.1.0",
"version": "1.2.0",
"description": "A customisable open-source Discord bot that brings the power of the XRPL to Discord communities.",
"repository": {
"type": "git",
Expand All @@ -16,7 +16,7 @@
"prestart": "npm run build",
"start": "node .",
"host": "node .",
"test": "jest"
"test": "jest --no-cache --forceExit"
},
"author": "ohonesix digital ltd",
"license": "GPL-3.0-only",
Expand All @@ -43,8 +43,9 @@
"@babel/core": "^7.20.12",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@types/jest": "^29.4.0",
"babel-jest": "^29.4.0",
"jest": "^29.4.0",
"ts-jest": "^29.0.5"
}
}
}
8 changes: 4 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SETTINGS from './settings.js';
import SETTINGS from './settings';

// tslint:disable-next-line
let appInsights = require('applicationinsights');
Expand All @@ -12,9 +12,9 @@ import bodyParser from 'body-parser';
import { Client, Intents, Message, Interaction } from 'discord.js';
import EventFactory from './events/EventFactory';
import { EventTypes } from './events/BotEvents';
import { scanLinkedWallets } from './business/scanLinkedWallets.js';
import { scanLinkedAccounts } from './business/scanLinkedAccounts.js';
import xummWebhook from './integration/xumm/webhook.js';
import { scanLinkedWallets } from './business/scanLinkedWallets';
import { scanLinkedAccounts } from './business/scanLinkedAccounts';
import xummWebhook from './integration/xumm/webhook';

// Discord Client
const discordClient = new Client({
Expand Down
10 changes: 5 additions & 5 deletions src/business/linkWalletToDiscordAccount.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getWalletHoldings } from '../integration/xrpl/getWalletHoldings.js';
import { updateUserWallet } from '../data/updateUserWallet.js';
import { updateUserRoles } from '../integration/discord/updateUserRoles.js';
import { getWalletHoldings } from '../integration/xrpl/getWalletHoldings';
import { updateUserWallet } from '../data/updateUserWallet';
import { updateUserRoles } from '../integration/discord/updateUserRoles';
import { Client, User } from 'discord.js';
import truncate from '../utils/truncate.js';
import { WalletUpdateResponse } from '../models/enum/WalletUpdateResponse.js';
import truncate from '../utils/truncate';
import { WalletUpdateResponse } from '../models/enum/WalletUpdateResponse';

const linkWalletToDiscordAccount = async (
walletAddress: string,
Expand Down
8 changes: 4 additions & 4 deletions src/business/scanLinkedAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sleep from '../utils/sleep.js';
import { getAllUsers } from '../data/getAllUsers.js';
import { updateUserAccount } from '../data/updateUserAccount.js';
import { getUserAccountById } from '../integration/discord/getUserAccountById.js';
import sleep from '../utils/sleep';
import { getAllUsers } from '../data/getAllUsers';
import { updateUserAccount } from '../data/updateUserAccount';
import { getUserAccountById } from '../integration/discord/getUserAccountById';
import { Client } from 'discord.js';

// Tracks users changing their Discord username
Expand Down
10 changes: 5 additions & 5 deletions src/business/scanLinkedWallets.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sleep from '../utils/sleep.js';
import { getAllUsers } from '../data/getAllUsers.js';
import { getWalletHoldings } from '../integration/xrpl/getWalletHoldings.js';
import { updateUser } from '../data/updateUser.js';
import { updateUserRoles } from '../integration/discord/updateUserRoles.js';
import sleep from '../utils/sleep';
import { getAllUsers } from '../data/getAllUsers';
import { getWalletHoldings } from '../integration/xrpl/getWalletHoldings';
import { updateUser } from '../data/updateUser';
import { updateUserRoles } from '../integration/discord/updateUserRoles';
import { Client } from 'discord.js';

// Scans user wallets and updates their roles
Expand Down
51 changes: 0 additions & 51 deletions src/commands/About.test.js

This file was deleted.

60 changes: 0 additions & 60 deletions src/commands/GetRoleUsers.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/commands/Unknown.ts

This file was deleted.

48 changes: 48 additions & 0 deletions src/commands/about.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import about from './about';
import { Message } from 'discord.js';

describe('about command logic', () => {
let message: Message;
let payload: any;

beforeEach(() => {
message = {
author: { id: '123' },
content: 'about',
reply: jest.fn(),
} as unknown as Message;

payload = {
handled: false,
message,
messageLowered: 'about',
};
});

afterEach(() => {
jest.resetAllMocks();
});

it('calls message.reply when payload.handled is false', async () => {
payload.handled = false;

await about(payload);

expect(message.reply).toHaveBeenCalled();
});

it('does not reply when payload.handled is true', async () => {
payload.handled = true;

await about(payload);

expect(message.reply).not.toHaveBeenCalled();
});

it('Responds to command with detail message', async () => {
const reply = `Based on the open-source bot https://ohonesix.com/xrpl-discord-bot which is available freely here https://github.com/jacobpretorius/XRPL-Discord-Bot`;

await about(payload);
expect(message.reply).toHaveBeenCalledWith(reply);
});
});
Loading

0 comments on commit 0d6f21e

Please sign in to comment.