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

Test suites creation 2 #11

Merged
merged 17 commits into from
Aug 18, 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
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ jobs:
uses: supercharge/mongodb-github-action@1.10.0
with:
mongodb-version: ${{ matrix.mongodb-version }}
mongodb-username: ssp-relay-user
mongodb-password: ssp-relay-password
mongodb-db: ssp-relay
- name: npm install
run: npm i
- name: Setup CI config
run: |
echo $SERVICE_ACCOUNT_CONFIG > config/serviceAccountKey.json
echo $API_SECRETS > config/apisecrets.ts
echo $ALCHEMY_SECRETS > config/alchemysecrets.ts
touch logs/debug.log logs/error.log logs/info.log
shell: bash
env:
SERVICE_ACCOUNT_CONFIG: ${{ secrets.SERVICE_ACCOUNT_CI }}
API_SECRETS: ${{ secrets.API_SECRETS }}
ALCHEMY_SECRETS: ${{ secrets.ALCHEMY_SECRETS }}
- name: Run tests and collect coverage
run: |
npm run test
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"start": "tsc && tsx index.ts",
"test": "nyc --reporter=lcov ts-mocha -p tsconfig.json tests/**/*.spec.ts",
"test": "nyc --reporter=lcov ts-mocha -p tsconfig.json tests/**/*.spec.ts --exit",
"lint": "eslint ./",
"lint:fix": "eslint ./ --fix",
"type-check": "tsc",
Expand Down Expand Up @@ -53,6 +53,8 @@
"ts-mocha": "~10.0.0",
"tsx": "~4.16.5",
"typescript": "~5.5.4",
"typescript-eslint": "~8.0.0"
"typescript-eslint": "~8.0.0",
"sinon": "~18.0.0",
"node-mocks-http": "~1.15.1"
}
}
2 changes: 1 addition & 1 deletion src/apiServices/ticketsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
throw new Error('No description specified');
}
if (!processedBody.subject) {
throw new Error('No subjet specified');
throw new Error('No subject specified');

Check warning on line 19 in src/apiServices/ticketsApi.ts

View check run for this annotation

Codecov / codecov/patch

src/apiServices/ticketsApi.ts#L19

Added line #L19 was not covered by tests
}
if (!processedBody.type) {
throw new Error('No type specified');
Expand Down
4 changes: 4 additions & 0 deletions src/services/networkFeesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,8 @@ async function networkFees(res) {
export default {
networkFees,
fetchFees,
obtainBitcoinFees,
obtainLitecoinFees,
obtainEthFees,
obtainSepoliaFees
};
6 changes: 5 additions & 1 deletion src/services/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface decodedTx {
fee?: string;
}

export async function sendNotificationKey(wkIdentity, data) {
async function sendNotificationKey(wkIdentity, data) {
try {
const syncs = await syncService.getTokens(wkIdentity);
let title = 'Transaction Request';
Expand Down Expand Up @@ -64,3 +64,7 @@ export async function sendNotificationKey(wkIdentity, data) {
log.error(error);
}
}

export default {
sendNotificationKey
}
2 changes: 0 additions & 2 deletions src/services/serviceHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ function ensureString(parameter) {
async function connectMongoDb(url?) {
const connectUrl = url || mongoUrl;
const mongoSettings = {
useNewUrlParser: true,
useUnifiedTopology: true,
maxPoolSize: 100,
};
const db = await MongoClient.connect(connectUrl, mongoSettings);
Expand Down
4 changes: 2 additions & 2 deletions src/services/transactionDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BigNumber from 'bignumber.js';
import utxolib from '@runonflux/utxo-lib';
import bchaddrjs from 'bchaddrjs';
import * as viem from 'viem';
import abi from '@runonflux/aa-schnorr-multisig-sdk/dist/abi';
import { MultiSigSmartAccount_abi } from '@runonflux/aa-schnorr-multisig-sdk/dist/abi';

import blockchains from './blockchains';
import log from '../lib/log';
Expand Down Expand Up @@ -40,7 +40,7 @@ function decodeEVMTransactionForApproval(rawTx, chain = 'eth') {
// callGasLimit":"0x5ea6","verificationGasLimit":"0x11b5a","preVerificationGas":"0xdf89","maxFeePerGas":"0xee6b28000","maxPriorityFeePerGas":"0x77359400",

const decodedData = viem.decodeFunctionData({
abi: abi.MultiSigSmartAccount_abi,
abi: MultiSigSmartAccount_abi,
data: callData,
});

Expand Down
199 changes: 199 additions & 0 deletions tests/unit/actionApi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/* eslint-disable @typescript-eslint/no-unused-expressions */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck test suite
import chai from 'chai';
import actionService from '../../src/services/actionService';
import serviceHelper from '../../src/services/serviceHelper';
import actionApi from '../../src/apiServices/actionApi';
import sinon from 'sinon';
import httpMocks from 'node-mocks-http';

const { expect, assert } = chai;

const reqValid = {
params: {
id: 141
},
query: {
id: 141
}
}

describe('Action API', () => {
describe('Get Action API: Correctly verifies action', () => {
afterEach(function() {
sinon.restore();
});

// Testing using stub data
it('should return successful result 141 if stub value is valid', async () => {
const request = httpMocks.createRequest({
method: 'GET',
url: 'test',
body: reqValid,
query: {id: 141}
});
const res = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req : request
});
await sinon.stub(actionService, "getAction").returns({ wkIdentity: 141});
await actionApi.getAction(request, res);
expect(JSON.parse(res._getData())).to.have.property('wkIdentity');
expect(JSON.parse(res._getData())).to.deep.equal({ wkIdentity: 141 });
});

it('should return Bad Request result 141 if stub value is invalid', async () => {
const request = httpMocks.createRequest({
method: 'GET',
url: 'test',
body: reqValid
});
const res = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req : request
});
await sinon.stub(actionService, "getAction").returns({ wkIdentity: 141});
await actionApi.getAction(request, res);
expect(res._getData()).to.deep.equal('Bad Request');
});

it('should return error result 141 if stub value is valid', async () => {
const request = httpMocks.createRequest({
method: 'GET',
url: 'test',
body: reqValid,
query: {id: 141}
});
const res = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req : request
});
await sinon.stub(actionService, "getAction").returns(false);
await actionApi.getAction(request, res);
expect(res._getData()).to.deep.equal('Not Found');
});
});

describe('Post Action: Correctly verifies action', () => {
afterEach(function() {
sinon.restore();
});

// Testing using stub data
it('should return error result if stub value has no chain', async () => {
const request = httpMocks.createRequest({
method: 'POST',
url: 'test',
body: reqValid,
});
const res = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req : request
});
await sinon.stub(serviceHelper, "ensureObject").returns({});
await sinon.stub(actionApi, "postAction").returns('Error: No Chain specified');
const data = await actionApi.postAction(request, res);
assert.equal(data, "Error: No Chain specified");
});

it('should return error result if stub value has no wallet key', async () => {
const request = httpMocks.createRequest({
method: 'POST',
url: 'test',
body: reqValid,
});
const res = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req : request
});
await sinon.stub(serviceHelper, "ensureObject").returns({chain: 1});
await sinon.stub(actionApi, "postAction").returns('Error: No Wallet-Key Identity specified');
const data = await actionApi.postAction(request, res);
assert.equal(data, "Error: No Wallet-Key Identity specified");
});

it('should return error result if stub value has no action', async () => {
const request = httpMocks.createRequest({
method: 'POST',
url: 'test',
body: reqValid,
});
const res = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req : request
});
await sinon.stub(serviceHelper, "ensureObject").returns({chain: 1, wkIdentity: 1});
await sinon.stub(actionApi, "postAction").returns('Error: No Action specified');
const data = await actionApi.postAction(request, res);
assert.equal(data, 'Error: No Action specified');
});

it('should return error result if stub value has no payload', async () => {
const request = httpMocks.createRequest({
method: 'POST',
url: 'test',
body: reqValid,
});
const res = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req : request
});
await sinon.stub(serviceHelper, "ensureObject").returns({chain: 1, wkIdentity: 1, action: "", });
await sinon.stub(actionApi, "postAction").returns('Error: No Payload specified');
const data = await actionApi.postAction(request, res);
assert.equal(data, 'Error: No Payload specified');
});

it('should return error result if stub value has no derivation', async () => {
const request = httpMocks.createRequest({
method: 'POST',
url: 'test',
body: reqValid,
});
const res = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req : request
});
await sinon.stub(serviceHelper, "ensureObject").returns({chain: 1, wkIdentity: 1, action: "", payload: ""});
await sinon.stub(actionApi, "postAction").returns('Error: No Derivation Path specified');
const data = await actionApi.postAction(request, res);
assert.equal(data, 'Error: No Derivation Path specified');
});

it('should return error result if stub value has no derivation', async () => {
const request = httpMocks.createRequest({
method: 'POST',
url: 'test',
body: reqValid,
});
const res = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req : request
});
await sinon.stub(serviceHelper, "ensureObject").returns({chain: 1, wkIdentity: 1, action: "tx", payload: "", path: ""});
await sinon.stub(actionService, "postAction").returns(false);
await sinon.stub(actionApi, "postAction").returns('Error: Failed to post action data');
const data = await actionApi.postAction(request, res);
assert.equal(data, 'Error: Failed to post action data');
});

it('should return successful result if stub value are valid', async () => {
const request = httpMocks.createRequest({
method: 'POST',
url: 'test',
body: reqValid,
});
const res = httpMocks.createResponse({
eventEmiiter: require('events').EventEmitter,
req : request
});
await sinon.stub(serviceHelper, "ensureObject").returns({chain: 1, wkIdentity: 1, action: "publicnoncesrequest", payload: "", path: ""});
await sinon.stub(actionService, "postAction").returns({chain: 1, wkIdentity: 1, action: "publicnoncesrequest", payload: "", path: ""});
await sinon.stub(actionApi, "postAction").returns({chain: 1, wkIdentity: 1, action: "publicnoncesrequest", payload: "", path: ""});
const data = await actionApi.postAction(request, res);
assert.deepEqual(data, {chain: 1, wkIdentity: 1, action: "publicnoncesrequest", payload: "", path: ""});
});

});
});
Loading
Loading