Skip to content
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
40 changes: 40 additions & 0 deletions __tests__/generateAccessToken.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { generateAccessToken } from '../src/promo-node-utils';
jest.setTimeout(40000);

describe('generateAccessToken no sub', () => {
const clientSecret = 'test client secret'; // never do this in your client side js but this is safe due to it being a testing application alone
const appId = 'test app id';
const clientId = 'test client id';
const hostName = 'http://localhost:3000';
let accessTokenSigned: string = generateAccessToken(
hostName,
clientId,
appId,
clientSecret
);

it('returns a string', async () => {
expect(typeof accessTokenSigned).toBe('string');
});
});

describe('generateAccessToken with sub and expiration', () => {
const clientSecret = 'test client secret'; // never do this in your client side js but this is safe due to it being a testing application alone
const appId = 'test app id';
const clientId = 'test client id';
const hostName = 'http://localhost:3000';
const sub = 'test@tincre.com';
const expiration = 123456
let accessTokenSigned: string = generateAccessToken(
hostName,
clientId,
appId,
clientSecret,
expiration,
sub
);

it('returns a string', async () => {
expect(typeof accessTokenSigned).toBe('string');
});
});
10 changes: 5 additions & 5 deletions __tests__/getToken.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { getToken } from '../src/.';
import { generateAccessToken } from './test-utils';
import { generateAccessToken } from '../src/promo-node-utils';
jest.setTimeout(40000);

describe('getToken', () => {
const clientSecret = '57hMbxBuIsWAMiT4k0XZ0JmQV5M0BrpR6E4nN9vbEoWvNy5S'; // never do this in your client side js but this is safe due to it being a testing application alone
const appId = 'ygzRl6CiiUivwsNn3UjntatUDP4k'
const clientId = 'm4MohkXSo2xMVWYXj6NecyS5uEeJ'
const hostName = 'http://localhost:3000'
const appId = 'ygzRl6CiiUivwsNn3UjntatUDP4k';
const clientId = 'm4MohkXSo2xMVWYXj6NecyS5uEeJ';
const hostName = 'http://localhost:3000';
let accessTokenSigned: string = generateAccessToken(
hostName,
clientId,
appId,
clientSecret,
clientSecret
);

it('returns a string', async () => {
Expand Down
5 changes: 3 additions & 2 deletions src/promo-node-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ function generateAccessToken(
clientId: string,
appId: string,
clientSecret: string,
expiration?: number
expiration?: number,
sub?: string
) {
const timestamp = Date.now();
const exp = expiration ? timestamp + expiration : timestamp + 1800;
let accessToken: PromoAccessTokenJwt = {
sub: '',
sub: sub || '',
iss: issuer,
cid: clientId,
aid: appId,
Expand Down