Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-jung1 committed Sep 18, 2024
1 parent c5cdf45 commit fc76dc0
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 111 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "error"
}
},
{
"files": ["./src/static/helpers/passwordlessHelper.ts"],
"rules": {
"@typescript-eslint/ban-types": "off"
}
}
],
"settings": {
Expand Down
153 changes: 78 additions & 75 deletions src/static/helpers/passwordlessHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import {
type slasHelperType = typeof slasHelper;
// Mock the module
jest.mock('./slasHelper', () => {
const actualUtils = jest.requireActual<slasHelperType>('./slasHelper');
const createCodeVerifierMock = jest.fn(() => 'code_verifier')
return {
...actualUtils,
createCodeVerifier: createCodeVerifierMock, // Mock the specific function
};
});
const actualUtils = jest.requireActual<slasHelperType>('./slasHelper');
const createCodeVerifierMock = jest.fn(() => 'code_verifier');
return {
...actualUtils,
createCodeVerifier: createCodeVerifierMock, // Mock the specific function
};
});

const authorizePasswordlessCustomerMock = jest.fn();
const getPasswordLessAccessTokenMock = jest.fn();
Expand Down Expand Up @@ -56,75 +56,78 @@ beforeEach(() => {
});

describe('authorizePasswordless is working', () => {
test('Correct parameters are used to call SLAS Client authorize', async () => {
const mockSlasClient = createMockSlasClient();
const {clientId, organizationId, siteId} = mockSlasClient.clientConfig.parameters;

const credentials = {
clientSecret: 'slas_private_secret',
};
const parameters = {
callbackURI: 'www.something.com/callback',
usid: 'a_usid',
userid: 'a_userid',
locale: 'a_locale',
mode: 'callback',
};
const authHeaderExpected = `Basic ${slasHelper.stringToBase64(
`${clientId}:${credentials.clientSecret}`
)}`;
await authorizePasswordless(mockSlasClient, credentials, parameters)
const expectedReqOptions = {
headers: {
Authorization: authHeaderExpected
},
parameters: {
organizationId
},
body: {
user_id: parameters.userid,
mode: parameters.mode,
locale: parameters.locale,
channel_id: siteId,
callback_uri: parameters.callbackURI,
usid: parameters.usid
}
}
expect(authorizePasswordlessCustomerMock).toBeCalledWith(expectedReqOptions);
});
test('Correct parameters are used to call SLAS Client authorize', async () => {
const mockSlasClient = createMockSlasClient();
const {clientId, organizationId, siteId} =
mockSlasClient.clientConfig.parameters;

const credentials = {
clientSecret: 'slas_private_secret',
};
const parameters = {
callbackURI: 'www.something.com/callback',
usid: 'a_usid',
userid: 'a_userid',
locale: 'a_locale',
mode: 'callback',
};
const authHeaderExpected = `Basic ${slasHelper.stringToBase64(
`${clientId}:${credentials.clientSecret}`
)}`;
await authorizePasswordless(mockSlasClient, credentials, parameters);
const expectedReqOptions = {
headers: {
Authorization: authHeaderExpected,
},
parameters: {
organizationId,
},
body: {
user_id: parameters.userid,
mode: parameters.mode,
locale: parameters.locale,
channel_id: siteId,
callback_uri: parameters.callbackURI,
usid: parameters.usid,
},
};
expect(authorizePasswordlessCustomerMock).toBeCalledWith(
expectedReqOptions, true

Check warning on line 95 in src/static/helpers/passwordlessHelper.test.ts

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Insert `⏎·····`

Check warning on line 95 in src/static/helpers/passwordlessHelper.test.ts

View workflow job for this annotation

GitHub Actions / linux-tests (14)

Insert `⏎·····`

Check warning on line 95 in src/static/helpers/passwordlessHelper.test.ts

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Insert `⏎·····`

Check warning on line 95 in src/static/helpers/passwordlessHelper.test.ts

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Insert `⏎·····`
);
});
});

describe('getPasswordLessAccessToken is working', () => {
test('Correct parameters are used to call SLAS Client authorize', async () => {
const mockSlasClient = createMockSlasClient();
const {clientId, organizationId} = mockSlasClient.clientConfig.parameters;
const credentials = {
clientSecret: 'slas_private_secret',
};
const parameters = {
pwdlessLoginToken: '123456',
dnt: '1'
};
const authHeaderExpected = `Basic ${slasHelper.stringToBase64(
`${clientId}:${credentials.clientSecret}`
)}`;
await getPasswordLessAccessToken(mockSlasClient, credentials, parameters)
const expectedReqOptions = {
headers: {
Authorization: authHeaderExpected
},
parameters: {
organizationId
},
body: {
dnt: parameters.dnt,
code_verifier: "code_verifier",
grant_type: 'client_credentials',
hint: 'pwdless_login',
pwdless_login_token: parameters.pwdlessLoginToken
}
}
expect(getPasswordLessAccessTokenMock).toBeCalledWith(expectedReqOptions);
});
test('Correct parameters are used to call SLAS Client authorize', async () => {
const mockSlasClient = createMockSlasClient();
const {clientId, organizationId} = mockSlasClient.clientConfig.parameters;

const credentials = {
clientSecret: 'slas_private_secret',
};
const parameters = {
pwdlessLoginToken: '123456',
dnt: '1',
};
const authHeaderExpected = `Basic ${slasHelper.stringToBase64(
`${clientId}:${credentials.clientSecret}`
)}`;
await getPasswordLessAccessToken(mockSlasClient, credentials, parameters);
const expectedReqOptions = {
headers: {
Authorization: authHeaderExpected,
},
parameters: {
organizationId,
},
body: {
dnt: parameters.dnt,
code_verifier: 'code_verifier',
grant_type: 'client_credentials',
hint: 'pwdless_login',
pwdless_login_token: parameters.pwdlessLoginToken,
},
};
expect(getPasswordLessAccessTokenMock).toBeCalledWith(expectedReqOptions);
});
});
63 changes: 33 additions & 30 deletions src/static/helpers/passwordlessHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function authorizePasswordless(
locale?: string;
mode: string;
}
): Promise<Response | Object> {
): Promise<Response> {
const authHeaderIdSecret = `Basic ${stringToBase64(
`${slasClient.clientConfig.parameters.clientId}:${credentials.clientSecret}`
)}`;
Expand All @@ -51,15 +51,18 @@ export async function authorizePasswordless(
...(parameters.callbackURI && {callback_uri: parameters.callbackURI}),
};

return slasClient.authorizePasswordlessCustomer({
headers: {
Authorization: authHeaderIdSecret,
},
parameters: {
organizationId: slasClient.clientConfig.parameters.organizationId,
return slasClient.authorizePasswordlessCustomer(
{
headers: {
Authorization: authHeaderIdSecret,
},
parameters: {
organizationId: slasClient.clientConfig.parameters.organizationId,
},
body: tokenBody,
},
body: tokenBody,
});
true
);
}

/**
Expand Down Expand Up @@ -87,27 +90,27 @@ export async function getPasswordLessAccessToken(
parameters: {
pwdlessLoginToken: string;
dnt?: string;
}
}
): Promise<TokenResponse> {
const codeVerifier = createCodeVerifier();
const authHeaderIdSecret = `Basic ${stringToBase64(
`${slasClient.clientConfig.parameters.clientId}:${credentials.clientSecret}`
)}`;
const codeVerifier = createCodeVerifier();
const authHeaderIdSecret = `Basic ${stringToBase64(
`${slasClient.clientConfig.parameters.clientId}:${credentials.clientSecret}`
)}`;

const tokenBody = {
grant_type: 'client_credentials',
hint: 'pwdless_login',
pwdless_login_token: parameters.pwdlessLoginToken,
code_verifier: codeVerifier,
...(parameters.dnt && {dnt: parameters.dnt}),
};
return slasClient.getPasswordLessAccessToken({
headers: {
Authorization: authHeaderIdSecret,
},
parameters: {
organizationId: slasClient.clientConfig.parameters.organizationId,
},
body: tokenBody,
});
const tokenBody = {
grant_type: 'client_credentials',
hint: 'pwdless_login',
pwdless_login_token: parameters.pwdlessLoginToken,
code_verifier: codeVerifier,
...(parameters.dnt && {dnt: parameters.dnt}),
};
return slasClient.getPasswordLessAccessToken({
headers: {
Authorization: authHeaderIdSecret,
},
parameters: {
organizationId: slasClient.clientConfig.parameters.organizationId,
},
body: tokenBody,
});
}

0 comments on commit fc76dc0

Please sign in to comment.