Skip to content
Open
48 changes: 24 additions & 24 deletions __tests__/api/cf/token.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe('cloudfoundry token tests', () => {
afterEach(() => {
delete process.env.CF_API_TOKEN;
});
it('getToken() returns a manual token', () => {
expect(getToken()).toBe('manual-token');
it('getToken() returns a manual token', async () => {
expect(await getToken()).toBe('manual-token');
});
});

Expand All @@ -29,24 +29,24 @@ describe('cloudfoundry token tests', () => {
get: () => ({ value: '{"accessToken":"cookie-token"}' }),
}));
});
it('getToken() returns a token from a cookie', () => {
expect(getToken()).toBe('cookie-token');
it('getToken() returns a token from a cookie', async () => {
expect(await getToken()).toBe('cookie-token');
});
it('isLoggedIn() returns true', () => {
expect(isLoggedIn()).toBeTruthy();
it('isLoggedIn() returns true', async () => {
expect(await isLoggedIn()).toBeTruthy();
});
});
describe('when auth cookie is not set', () => {
beforeEach(() => {
cookies.mockImplementation(() => ({
cookies.mockImplementation(async () => ({
get: () => undefined,
}));
});
it('getToken() throws an error when no cookie is set', () => {
expect(() => getToken()).toThrow('please confirm you are logged in');
it('getToken() throws an error when no cookie is set', async () => {
expect(await getToken()).toThrow('please confirm you are logged in');
});
it('isLoggedIn() returns false', () => {
expect(isLoggedIn()).toBeFalsy();
it('isLoggedIn() returns false', async () => {
expect(await isLoggedIn()).toBeFalsy();
});
});
describe('when auth cookie is not in an expected format', () => {
Expand All @@ -55,11 +55,11 @@ describe('cloudfoundry token tests', () => {
get: () => 'unexpected format',
}));
});
it('getToken() throws an error', () => {
expect(() => getToken()).toThrow('unable to parse accessToken');
it('getToken() throws an error', async () => {
expect(await getToken()).toThrow('unable to parse accessToken');
});
it('isLoggedIn() returns falsee', () => {
expect(isLoggedIn()).toBeFalsy();
it('isLoggedIn() returns falsee', async () => {
expect(await isLoggedIn()).toBeFalsy();
});
});
});
Expand All @@ -73,8 +73,8 @@ describe('cloudfoundry user id tests', () => {
afterEach(() => {
delete process.env.CF_USER_ID;
});
it('getUserId() returns a manual token', () => {
expect(getUserId()).toBe('foo-user-id');
it('getUserId() returns a manual token', async () => {
expect(await getUserId()).toBe('foo-user-id');
});
});

Expand All @@ -85,18 +85,18 @@ describe('cloudfoundry user id tests', () => {
get: () => ({ value: '{"user_id":"foo-user-id"}' }),
}));
});
it('getUserId() returns a token from a cookie', () => {
expect(getUserId()).toBe('foo-user-id');
it('getUserId() returns a token from a cookie', async () => {
expect(await getUserId()).toBe('foo-user-id');
});
});
describe('when auth cookie is not set', () => {
beforeEach(() => {
cookies.mockImplementation(() => ({
cookies.mockImplementation(async () => ({
get: () => undefined,
}));
});
it('getToken() throws an error when no cookie is set', () => {
expect(() => getUserId()).toThrow('please confirm you are logged in');
it.only('getToken() throws an error when no cookie is set', async () => {
expect(await getUserId()).toThrow('please confirm you are logged in');
});
});
describe('when auth cookie is not in an expected format', () => {
Expand All @@ -105,8 +105,8 @@ describe('cloudfoundry user id tests', () => {
get: () => 'unexpected format',
}));
});
it('getToken() throws an error', () => {
expect(() => getUserId()).toThrow(
it('getToken() throws an error', async () => {
expect(await getUserId()).toThrow(
'unable to parse authsession user_id'
);
});
Expand Down
3 changes: 2 additions & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference path="./.next/types/routes.d.ts" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
Loading
Loading