Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: convert to TS #600

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:

mongosh --eval 'db.getSiblingDB("lnp2pbot").createCollection("mycollection")'

- run: npm install @types/node @types/i18n
- run: npm install @types/node @types/i18n @types/mocha
- run: npx tsc
- run: npm ci
- name: Run tests
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Please note that Pull Requests marked `NACK` and/or GitHub's `Change requested`

We ~~try to~~ use [Airbnb javascript style guide](https://github.com/airbnb/javascript) in order to have a cleaner code.

All new code should be TypeScript. The use of `any` type is discouraged, except in the tests.

### Configure Git user name and email metadata

See https://help.github.com/articles/setting-your-username-in-git/ for instructions.
Expand Down
34 changes: 17 additions & 17 deletions tests/bot/bot.spec.js → tests/bot/bot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const path = require('path');
const fs = require('fs');
import path from 'path';
import fs from 'fs';
const sinon = require('sinon');
const { expect } = require('chai');
const proxyquire = require('proxyquire');

const { initialize } = require('../../bot');
const { User, Order } = require('../../models');
const { getCurrenciesWithPrice } = require('../../util');
const { mockUpdatesResponseForCurrencies } = require('./mocks/currenciesResponse');
const { mockUpdatesResponseForLanguages } = require('./mocks/languagesResponse');
import { User, Order } from '../../models';
import { getCurrenciesWithPrice } from '../../util';
import { mockUpdatesResponseForCurrencies } from './mocks/currenciesResponse';
import { mockUpdatesResponseForLanguages } from './mocks/languagesResponse';

describe('Telegram bot', () => {
const token = '123456';
let server;
let sandbox;
let server: any;
let sandbox: any;
let order, user;

beforeEach(() => {
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('Telegram bot', () => {
const updates = await client.getUpdates();
expect(updates.ok).to.be.equal(true);
let flags = 0;
updates.result[0].message.reply_markup.inline_keyboard.forEach(flag => {
updates.result[0].message.reply_markup.inline_keyboard.forEach((flag: any) => {
flags += flag.length;
});
let langs = 0;
Expand All @@ -206,12 +206,12 @@ describe('Telegram bot', () => {
});

describe('Bot Initialization', () => {
let initialize;
let botStub;
let scheduleStub;
let validateUserStub;
let startMessageStub;
let attemptPendingPaymentsStub;
let initialize: any;
let botStub: any;
let scheduleStub: any;
let validateUserStub: any;
let startMessageStub: any;
let attemptPendingPaymentsStub: any;

beforeEach(() => {
botStub = {
Expand Down Expand Up @@ -501,7 +501,7 @@ describe('Bot Initialization', () => {
},
};

botStub.on = sinon.stub().callsFake((event, middleware, handler) => {
botStub.on = sinon.stub().callsFake((event: string, middleware: any, handler: any) => {
if (event === 'text') {
const capturedHandler = handler;
capturedHandler(ctx);
Expand Down Expand Up @@ -563,7 +563,7 @@ describe('Bot Initialization', () => {
},
};

botStub.on = sinon.stub().callsFake((event, middleware, handler) => {
botStub.on = sinon.stub().callsFake((event: string, middleware: any, handler: any) => {
if (event === 'text') {
const capturedHandler = handler;
capturedHandler(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ const mockUpdatesResponseForCurrencies = {
]
};

module.exports = {
export {
mockUpdatesResponseForCurrencies,
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ const mockUpdatesResponseForLanguages = {
}]
};

module.exports = {
export {
mockUpdatesResponseForLanguages,
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const mockTelegram = {
};

const mockI18n = {
t: sinon.stub((key, params) => {
t: sinon.stub((key: string, params: any) => {
switch (key) {
case 'dispute_started_channel':
return `User ${params.type} @${params.initiatorUser} TG ID: ${params.initiatorTgId}
Expand Down
Loading
Loading