Skip to content

Commit f742b5e

Browse files
committed
refactor
1 parent 41c859d commit f742b5e

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

src/static/helpers/slasHelper.test.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,27 @@ describe('authorizePasswordless is working', () => {
949949
);
950950
});
951951

952+
test('Throw when required userid missing', async () => {
953+
const mockSlasClient = createMockSlasClient();
954+
const parametersAuthorizePasswordless = {
955+
callbackURI: 'www.something.com/callback',
956+
usid: 'a_usid',
957+
locale: 'a_locale',
958+
mode: 'callback',
959+
};
960+
await expect(
961+
slasHelper.authorizePasswordless({
962+
slasClient: mockSlasClient,
963+
credentials: credentialsPrivate,
964+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
965+
// @ts-ignore intentionally missing userid
966+
parameters: parametersAuthorizePasswordless,
967+
})
968+
).rejects.toThrow(
969+
'Required argument userid is not provided through parameters'
970+
);
971+
});
972+
952973
test('Throw when clientSecret is missing', async () => {
953974
const mockSlasClient = createMockSlasClient();
954975
const parametersAuthorizePasswordless = {
@@ -1037,6 +1058,34 @@ describe('getPasswordLessAccessToken is working', () => {
10371058
'Required argument organizationId is not provided through clientConfig.parameters.organizationId'
10381059
);
10391060
});
1061+
1062+
test('Throw when clientSecret is missing', async () => {
1063+
const mockSlasClient = createMockSlasClient();
1064+
await expect(
1065+
slasHelper.getPasswordLessAccessToken({
1066+
slasClient: mockSlasClient,
1067+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1068+
// @ts-ignore intentionally missing clientSecret
1069+
credentials: {},
1070+
parameters: {pwdlessLoginToken: '123456'},
1071+
})
1072+
).rejects.toThrow('Required argument client secret is not provided');
1073+
});
1074+
1075+
test('Throw when pwdlessLoginToken is missing', async () => {
1076+
const mockSlasClient = createMockSlasClient();
1077+
await expect(
1078+
slasHelper.getPasswordLessAccessToken({
1079+
slasClient: mockSlasClient,
1080+
credentials: credentialsPrivate,
1081+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1082+
// @ts-ignore intentionally missing pwdlessLoginToken
1083+
parameters: {},
1084+
})
1085+
).rejects.toThrow(
1086+
'Required argument pwdlessLoginToken is not provided through parameters'
1087+
);
1088+
});
10401089
});
10411090

10421091
describe('Refresh Token', () => {
@@ -1340,4 +1389,40 @@ describe('httpOnly session cookies', () => {
13401389
delete global.btoa;
13411390
jest.restoreAllMocks();
13421391
});
1392+
1393+
test('throws ResponseError when httpOnly raw response is not ok', async () => {
1394+
const mockGetAccessToken = jest.fn(() => ({
1395+
ok: false,
1396+
status: 401,
1397+
text: jest.fn().mockResolvedValue('Unauthorized'),
1398+
headers: {
1399+
get: jest.fn(() => null),
1400+
},
1401+
}));
1402+
const mockSlasClient = {
1403+
clientConfig: {
1404+
parameters: {
1405+
shortCode: 'short_code',
1406+
organizationId: 'organization_id',
1407+
clientId: 'client_id',
1408+
siteId: 'site_id',
1409+
},
1410+
},
1411+
getAccessToken: mockGetAccessToken,
1412+
} as unknown as ShopperLogin<{
1413+
shortCode: string;
1414+
organizationId: string;
1415+
clientId: string;
1416+
siteId: string;
1417+
}>;
1418+
1419+
await expect(
1420+
slasHelper.loginGuestUserPrivate({
1421+
slasClient: mockSlasClient,
1422+
parameters: {},
1423+
credentials: {clientSecret: 'slas_private_secret'},
1424+
enableHttpOnlySessionCookies: true,
1425+
})
1426+
).rejects.toThrow(ResponseError);
1427+
});
13431428
});

0 commit comments

Comments
 (0)