diff --git a/__tests__/generateAccessToken.test.ts b/__tests__/generateAccessToken.test.ts new file mode 100644 index 0000000..44b1bd4 --- /dev/null +++ b/__tests__/generateAccessToken.test.ts @@ -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'); + }); +}); diff --git a/__tests__/getToken.test.ts b/__tests__/getToken.test.ts index 5ea7023..e49054d 100644 --- a/__tests__/getToken.test.ts +++ b/__tests__/getToken.test.ts @@ -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 () => { diff --git a/src/promo-node-utils.ts b/src/promo-node-utils.ts index b810c60..d58387a 100644 --- a/src/promo-node-utils.ts +++ b/src/promo-node-utils.ts @@ -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,