Skip to content

Commit

Permalink
fixed testing
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulhakim2902 committed Dec 13, 2021
1 parent 80e8c6b commit 346668f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/__tests__/acceptance/people.acceptance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {EntityNotFoundError} from '@loopback/repository';
import {Client, expect, toJSON} from '@loopback/testlab';
import {MyriadApiApplication} from '../../application';
import {PlatformType} from '../../enums';
import {People} from '../../models';
import {
PeopleRepository,
Expand Down Expand Up @@ -95,7 +96,7 @@ describe('PeopleApplication', function () {
const peopleInProgress = await givenPeopleInstance(peopleRepository, {
name: 'W3F_Bill',
username: 'W3F_Bill',
platform: 'reddit',
platform: PlatformType.REDDIT,
originUserId: 't2_5turjfiq',
profilePictureURL:
'https://styles.redditmedia.com/t5_2gskf7/styles/profileIcon_snoof1dc48fa-83bd-4ed3-8ef3-56f2469da2ce-headshot.png',
Expand All @@ -119,7 +120,7 @@ describe('PeopleApplication', function () {
await givenPeopleInstance(peopleRepository, {
name: 'CryptoChief',
username: 'CryptoChief',
platform: 'reddit',
platform: PlatformType.REDDIT,
originUserId: 't2_e0t5q',
profilePictureURL:
'https://www.redditstatic.com/avatars/avatar_default_15_DB0064.png',
Expand Down
34 changes: 28 additions & 6 deletions src/__tests__/acceptance/post-walletaddress.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ import {
givenUserSocialMediaRepository,
setupApplication,
} from '../helpers';
import {promisify} from 'util';
import {genSalt, hash} from 'bcryptjs';
import {config} from '../../config';
import {PolkadotJs} from '../../utils/polkadotJs-utils';

const jwt = require('jsonwebtoken');
const signAsync = promisify(jwt.sign);

describe('PostWalletAddressApplication', function () {
let app: MyriadApiApplication;
Expand Down Expand Up @@ -54,19 +61,34 @@ describe('PostWalletAddressApplication', function () {
});

it('gets a post wallet address from people', async () => {
const password = people.id + config.ESCROW_SECRET_KEY;
const salt = await genSalt(10);
const hashPassword = await hash(password, salt);

await postRepository.updateById(post.id, {peopleId: people.id});
await peopleRepository.updateById(people.id, {
walletAddress:
'0x06cc7ed22ebd12ccc28fb9c0d14a5c4420a331d89a5fef48b915e8449ee61824',
walletAddressPassword: hashPassword,
});
const result = await client
.get(`/posts/${post.id}/walletaddress`)
.send()
.expect(200);

const token = await signAsync(
{
id: people.id,
originUserId: people.originUserId,
platform: people.platform,
iat: new Date(people.createdAt ?? '').getTime(),
},
config.ESCROW_SECRET_KEY,
);

const {getKeyring, getHexPublicKey} = new PolkadotJs();
const newKey = getKeyring().addFromUri('//' + token);

expect(result.body).to.deepEqual({
walletAddress:
'0x06cc7ed22ebd12ccc28fb9c0d14a5c4420a331d89a5fef48b915e8449ee61824',
walletAddress: getHexPublicKey(newKey),
});
});

Expand All @@ -92,9 +114,9 @@ describe('PostWalletAddressApplication', function () {
expect(result.body).to.deepEqual({walletAddress: myriadPost.createdBy});
});

it('returns 404 when wallet address not found', async () => {
it('returns 401 and 404 when wallet address not found', async () => {
await client.get(`/posts/${post.id}/walletaddress`).send().expect(404);
await postRepository.updateById(post.id, {peopleId: people.id});
await client.get(`/posts/${post.id}/walletaddress`).send().expect(404);
await client.get(`/posts/${post.id}/walletaddress`).send().expect(401);
});
});
4 changes: 2 additions & 2 deletions src/__tests__/helpers/given-instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export async function givenMultiplePeopleInstances(
givenPeopleInstance(peopleRepository, {
name: 'Gavin Wood',
username: 'gavofyork',
platform: 'twitter',
platform: PlatformType.TWITTER,
originUserId: '33962758',
profilePictureURL:
'https://pbs.twimg.com/profile_images/981390758870683656/RxA_8cyN_400x400.jpg',
Expand Down Expand Up @@ -559,7 +559,7 @@ export async function givenMultipleExperienceInstances(
id: '60efac8c565ab8004ed28ba7',
name: 'Gavin Wood',
username: 'gavofyork',
platform: 'twitter',
platform: PlatformType.TWITTER,
originUserId: '33962758',
profilePictureURL:
'https://pbs.twimg.com/profile_images/981390758870683656/RxA_8cyN_400x400.jpg',
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/unit/experience.controllet.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
toJSON,
} from '@loopback/testlab';
import {ExperienceController} from '../../controllers';
import {PlatformType} from '../../enums';
import {Experience, People} from '../../models';
import {ExperienceRepository} from '../../repositories';
import {givenExperience} from '../helpers';
Expand Down Expand Up @@ -70,7 +71,7 @@ describe('ExperienceController', () => {
id: '60efac8c565ab8004ed28ba7',
name: 'Gavin Wood',
username: 'gavofyork',
platform: 'twitter',
platform: PlatformType.TWITTER,
originUserId: '33962758',
profilePictureURL:
'https://pbs.twimg.com/profile_images/981390758870683656/RxA_8cyN_400x400.jpg',
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/unit/people.controller.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
toJSON,
} from '@loopback/testlab';
import {PeopleController} from '../../controllers';
import {PlatformType} from '../../enums';
import {People} from '../../models';
import {PeopleRepository, UserRepository} from '../../repositories';
import {givenPeople} from '../helpers';
Expand Down Expand Up @@ -77,7 +78,7 @@ describe('PeopleController', () => {
id: '2',
name: 'Gavin Wood',
username: 'gavofyork',
platform: 'twitter',
platform: PlatformType.TWITTER,
originUserId: '33962758',
profilePictureURL:
'https://pbs.twimg.com/profile_images/981390758870683656/RxA_8cyN_400x400.jpg',
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const config = {
MYRIAD_MNEMONIC: process.env.MYRIAD_FAUCET_MNEMONIC ?? generateSeed(),
MYRIAD_REWARD_AMOUNT: +(process.env.MYRIAD_REWARD_AMOUNT ?? 0),

ESCROW_SECRET_KEY: process.env.ESCROW_SECRET_KEY ?? '',
ESCROW_SECRET_KEY: process.env.ESCROW_SECRET_KEY ?? 's3cr3+<3y',

ACALA_AUSD_REWARD_AMOUNT: +(process.env.ACALA_AUSD_REWARD_AMOUNT ?? 0),

Expand Down

0 comments on commit 346668f

Please sign in to comment.