diff --git a/src/__tests__/acceptance/people.acceptance.ts b/src/__tests__/acceptance/people.acceptance.ts index 28e88df9b..1aea58a0c 100644 --- a/src/__tests__/acceptance/people.acceptance.ts +++ b/src/__tests__/acceptance/people.acceptance.ts @@ -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, @@ -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', @@ -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', diff --git a/src/__tests__/acceptance/post-walletaddress.acceptance.ts b/src/__tests__/acceptance/post-walletaddress.acceptance.ts index d9de2052a..d03330fe8 100644 --- a/src/__tests__/acceptance/post-walletaddress.acceptance.ts +++ b/src/__tests__/acceptance/post-walletaddress.acceptance.ts @@ -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; @@ -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), }); }); @@ -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); }); }); diff --git a/src/__tests__/helpers/given-instances.ts b/src/__tests__/helpers/given-instances.ts index b6d9f8745..40d4f24b6 100644 --- a/src/__tests__/helpers/given-instances.ts +++ b/src/__tests__/helpers/given-instances.ts @@ -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', @@ -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', diff --git a/src/__tests__/unit/experience.controllet.unit.ts b/src/__tests__/unit/experience.controllet.unit.ts index ae87e1b3f..fd5a7edc7 100644 --- a/src/__tests__/unit/experience.controllet.unit.ts +++ b/src/__tests__/unit/experience.controllet.unit.ts @@ -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'; @@ -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', diff --git a/src/__tests__/unit/people.controller.unit.ts b/src/__tests__/unit/people.controller.unit.ts index 7875a505e..9b4197e7c 100644 --- a/src/__tests__/unit/people.controller.unit.ts +++ b/src/__tests__/unit/people.controller.unit.ts @@ -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'; @@ -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', diff --git a/src/config.ts b/src/config.ts index 9b63bec80..802f23bb3 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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),