Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Kpoke committed Jul 18, 2022
1 parent 982692b commit f975dc7
Show file tree
Hide file tree
Showing 59 changed files with 956 additions and 1,005 deletions.
2 changes: 1 addition & 1 deletion __tests__/bundle-transfer-create-accept.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('Create and accept a bundle transfer', () => {
.set('Authorization', `Bearer ${bearerTokenB}`);
expect(res).to.have.property('statusCode', 200);
expect(res.body.transfers).lengthOf(1);
pendingTransfer = res.body.transfers[0];
[pendingTransfer] = res.body.transfers;
expect(pendingTransfer)
.property('destination_wallet')
.eq(seed.walletB.name);
Expand Down
2 changes: 1 addition & 1 deletion __tests__/bundle-transfer-decline.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('Create and decline a bundle transfer', () => {
.set('Authorization', `Bearer ${bearerTokenB}`);
expect(res).to.have.property('statusCode', 200);
expect(res.body.transfers).lengthOf(1);
pendingTransfer = res.body.transfers[0];
[pendingTransfer] = res.body.transfers;
expect(pendingTransfer)
.property('destination_wallet')
.eq(seed.walletB.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ const headers = (token) => {
};
};

const payload = (walletA, walletB) => {
const payload = (senderWallet, receiverWalletB) => {
return {
bundle: {
bundle_size: 1,
},
sender_wallet: walletA,
receiver_wallet: walletB,
sender_wallet: senderWallet,
receiver_wallet: receiverWalletB,
claim: false,
};
};
Expand Down
5 changes: 3 additions & 2 deletions __tests__/e2e/__tests__/wallets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ describe('Wallets (Wallet API)', function () {
const { wallets } = response.body;
assert.equals(response.status, OK, 'Created Wallet not found');

for (const wallet of wallets) {
if (Object.values(wallet).includes(expectedWallet)) {
for (let i = 0; i < wallets.length; i += 1) {
const w = wallets[i];
if (Object.values(w).includes(expectedWallet)) {
walletCreated = true;
break;
}
Expand Down
8 changes: 5 additions & 3 deletions __tests__/e2e/config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require('dotenv').config();

const supertest = require('supertest');
const { expect } = require('chai');
const responseStatus = require('http-status-codes');
const server = process.env.RUN_E2E_LOCALLY
? require('../../server/app')
: `https://${process.env.ENVIRONMENT}-k8s.treetracker.org/wallet`;
const request = require('supertest')(server);
const { expect } = require('chai');
const responseStatus = require('http-status-codes');

const request = supertest(server);
const assert = require('./libs/assertionLibrary.js');
const seed = require('./database/seed.js');

Expand Down
153 changes: 80 additions & 73 deletions __tests__/e2e/database/seed.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,71 @@
/*
* seed data to DB for testing
*/
const uuid = require("uuid");
const log = require('loglevel');
const uuid = require('uuid');
const { v4: uuidV4 } = require('uuid');
const knex = require("./knex");
const knex = require('./knex');

const apiKey = "FORTESTFORTESTFORTESTFORTESTFORTEST";
const apiKey = 'FORTESTFORTESTFORTESTFORTESTFORTEST';

const wallet = {
id: uuid.v4(),
name: "walletA",
password: "test1234",
name: 'walletA',
password: 'test1234',
passwordHash:
"31dd4fe716e1a908f0e9612c1a0e92bfdd9f66e75ae12244b4ee8309d5b869d435182f5848b67177aa17a05f9306e23c10ba41675933e2cb20c66f1b009570c1",
salt: "TnDe2LDPS7VaPD9GQWL3fhG4jk194nde",
type: "p",
'31dd4fe716e1a908f0e9612c1a0e92bfdd9f66e75ae12244b4ee8309d5b869d435182f5848b67177aa17a05f9306e23c10ba41675933e2cb20c66f1b009570c1',
salt: 'TnDe2LDPS7VaPD9GQWL3fhG4jk194nde',
type: 'p',
};

const walletB = {
id: uuid.v4(),
name: "walletB",
password: "test1234",
name: 'walletB',
password: 'test1234',
passwordHash:
"31dd4fe716e1a908f0e9612c1a0e92bfdd9f66e75ae12244b4ee8309d5b869d435182f5848b67177aa17a05f9306e23c10ba41675933e2cb20c66f1b009570c1",
salt: "TnDe2LDPS7VaPD9GQWL3fhG4jk194nde",
type: "p",
'31dd4fe716e1a908f0e9612c1a0e92bfdd9f66e75ae12244b4ee8309d5b869d435182f5848b67177aa17a05f9306e23c10ba41675933e2cb20c66f1b009570c1',
salt: 'TnDe2LDPS7VaPD9GQWL3fhG4jk194nde',
type: 'p',
};

const walletC = {
id: uuid.v4(),
name: "walletC",
password: "test1234",
name: 'walletC',
password: 'test1234',
passwordHash:
"31dd4fe716e1a908f0e9612c1a0e92bfdd9f66e75ae12244b4ee8309d5b869d435182f5848b67177aa17a05f9306e23c10ba41675933e2cb20c66f1b009570c1",
salt: "TnDe2LDPS7VaPD9GQWL3fhG4jk194nde",
type: "p",
'31dd4fe716e1a908f0e9612c1a0e92bfdd9f66e75ae12244b4ee8309d5b869d435182f5848b67177aa17a05f9306e23c10ba41675933e2cb20c66f1b009570c1',
salt: 'TnDe2LDPS7VaPD9GQWL3fhG4jk194nde',
type: 'p',
};

const walletTrustD = {
id: uuid.v4(),
name: "walletD",
password: "test1234",
name: 'walletD',
password: 'test1234',
passwordHash:
"31dd4fe716e1a908f0e9612c1a0e92bfdd9f66e75ae12244b4ee8309d5b869d435182f5848b67177aa17a05f9306e23c10ba41675933e2cb20c66f1b009570c1",
salt: "TnDe2LDPS7VaPD9GQWL3fhG4jk194nde",
type: "p",
'31dd4fe716e1a908f0e9612c1a0e92bfdd9f66e75ae12244b4ee8309d5b869d435182f5848b67177aa17a05f9306e23c10ba41675933e2cb20c66f1b009570c1',
salt: 'TnDe2LDPS7VaPD9GQWL3fhG4jk194nde',
type: 'p',
};

const walletTrustE = {
id: uuid.v4(),
name: "walletE",
password: "test1234",
name: 'walletE',
password: 'test1234',
passwordHash:
"31dd4fe716e1a908f0e9612c1a0e92bfdd9f66e75ae12244b4ee8309d5b869d435182f5848b67177aa17a05f9306e23c10ba41675933e2cb20c66f1b009570c1",
salt: "TnDe2LDPS7VaPD9GQWL3fhG4jk194nde",
type: "p",
'31dd4fe716e1a908f0e9612c1a0e92bfdd9f66e75ae12244b4ee8309d5b869d435182f5848b67177aa17a05f9306e23c10ba41675933e2cb20c66f1b009570c1',
salt: 'TnDe2LDPS7VaPD9GQWL3fhG4jk194nde',
type: 'p',
};

const managingWallet = {
id: uuid.v4(),
name: "managingWallet",
password: "test1234",
name: 'managingWallet',
password: 'test1234',
passwordHash:
"31dd4fe716e1a908f0e9612c1a0e92bfdd9f66e75ae12244b4ee8309d5b869d435182f5848b67177aa17a05f9306e23c10ba41675933e2cb20c66f1b009570c1",
salt: "TnDe2LDPS7VaPD9GQWL3fhG4jk194nde",
type: "p",
'31dd4fe716e1a908f0e9612c1a0e92bfdd9f66e75ae12244b4ee8309d5b869d435182f5848b67177aa17a05f9306e23c10ba41675933e2cb20c66f1b009570c1',
salt: 'TnDe2LDPS7VaPD9GQWL3fhG4jk194nde',
type: 'p',
};

const capture = {
Expand All @@ -77,9 +78,9 @@ const token = {

async function createTokens(targetWallet, numberOfTokens) {
const tokenIds = [];
for(let i = 0; i < numberOfTokens; i++) {
for (let i = 0; i < numberOfTokens; i += 1) {
const tokenId = uuidV4();
await knex("token").insert({
await knex('token').insert({
id: tokenId,
capture_id: uuidV4(),
wallet_id: targetWallet,
Expand All @@ -90,101 +91,107 @@ async function createTokens(targetWallet, numberOfTokens) {
}

async function seed() {
console.log("seed api key");
await knex("api_key").insert({
log.log('seed api key');
await knex('api_key').insert({
key: apiKey,
tree_token_api_access: true,
hash: "test",
salt: "test",
name: "test",
hash: 'test',
salt: 'test',
name: 'test',
});

// wallet
await knex("wallet").insert({
await knex('wallet').insert({
id: wallet.id,
name: wallet.name,
password: wallet.passwordHash,
salt: wallet.salt,
});

// walletB
await knex("wallet").insert({
await knex('wallet').insert({
id: walletB.id,
name: walletB.name,
password: walletB.passwordHash,
salt: walletB.salt,
});

// walletC
await knex("wallet").insert({
await knex('wallet').insert({
id: walletC.id,
name: walletC.name,
password: walletC.passwordHash,
salt: walletC.salt,
});

// walletD
await knex("wallet").insert({
await knex('wallet').insert({
id: walletTrustD.id,
name: walletTrustD.name,
password: walletTrustD.passwordHash,
salt: walletTrustD.salt,
});

// walletE
await knex("wallet").insert({
await knex('wallet').insert({
id: walletTrustE.id,
name: walletTrustE.name,
password: walletTrustE.passwordHash,
salt: walletTrustE.salt,
});

// managing wallet
await knex("wallet").insert({
await knex('wallet').insert({
id: managingWallet.id,
name: managingWallet.name,
password: managingWallet.passwordHash,
salt: managingWallet.salt,
});

// token
console.log("seed token");
log.log('seed token');

await createTokens(wallet.id, 5);
await createTokens(walletTrustD.id, 2);

await knex("token").insert({
await knex('token').insert({
id: token.id,
capture_id: capture.id,
wallet_id: wallet.id,
});
}

async function clear(wallets) {
console.log("clearing db");

await knex("api_key").where("key", apiKey).del();

for (const wallet of wallets) {
await knex("transaction").where("source_wallet_id", wallet).del();
}

for (const wallet of wallets) {
await knex("token").where("wallet_id", wallet).del();
}

await knex("wallet").where("name", wallet.name).del();
await knex("wallet").where("name", walletB.name).del();
await knex("wallet").where("name", walletC.name).del();
await knex("wallet").where("name", walletTrustD.name).del();
await knex("wallet").where("name", walletTrustE.name).del();
await knex("wallet").where("name", managingWallet.name).del();

for (const wallet of wallets) {
await knex("wallet_trust").where("actor_wallet_id", wallet).del();
}

console.log("done clearing db");
log.log('clearing db');

await knex('api_key').where('key', apiKey).del();

await Promise.all(
wallets.map(async (w) => {
await knex('transaction').where('source_wallet_id', w).del();
}),
);

await Promise.all(
wallets.map(async (w) => {
await knex('token').where('wallet_id', w).del();
}),
);

await knex('wallet').where('name', wallet.name).del();
await knex('wallet').where('name', walletB.name).del();
await knex('wallet').where('name', walletC.name).del();
await knex('wallet').where('name', walletTrustD.name).del();
await knex('wallet').where('name', walletTrustE.name).del();
await knex('wallet').where('name', managingWallet.name).del();

await Promise.all(
wallets.map(async (w) => {
await knex('wallet_trust').where('actor_wallet_id', w).del();
}),
);

log.log('done clearing db');
}

module.exports = {
Expand All @@ -198,5 +205,5 @@ module.exports = {
walletTrustE,
managingWallet,
capture,
token
token,
};
Loading

0 comments on commit f975dc7

Please sign in to comment.