Skip to content

Commit

Permalink
update test client
Browse files Browse the repository at this point in the history
  • Loading branch information
yunakim714 committed Oct 1, 2024
1 parent 7dc6a31 commit fc34ee3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@
"bundlesize": [
{
"path": "lib/**/*.js",
"maxSize": "53 kB"
"maxSize": "50 kB"
},
{
"path": "commerce-sdk-isomorphic-with-deps.tgz",
"maxSize": "450 kB"
"maxSize": "430 kB"
}
],
"proxy": "https://SHORTCODE.api.commercecloud.salesforce.com"
Expand Down
13 changes: 3 additions & 10 deletions src/static/helpers/slasHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,22 +261,15 @@ test('throws error on 400 response', async () => {
describe('Authorize IDP User', () => {
test('returns authorization url for 3rd party idp login', async () => {
const mockSlasClient = createMockSlasClient();
const {shortCode, organizationId} = mockSlasClient.clientConfig.parameters;

// slasClient is copied and tries to make an actual API call
nock(`https://${shortCode}.api.commercecloud.salesforce.com`)
.get(`/shopper/auth/v1/organizations/${organizationId}/oauth2/authorize`)
.query(true)
.reply(303, {response_body: 'response_body'}, {location: url});
mockSlasClient.clientConfig.baseUri = 'https://{shortCode}.api.commercecloud.salesforce.com/shopper/auth/{version}';

Check warning on line 264 in src/static/helpers/slasHelper.test.ts

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Insert `⏎·····`

Check warning on line 264 in src/static/helpers/slasHelper.test.ts

View workflow job for this annotation

GitHub Actions / linux-tests (14)

Insert `⏎·····`

Check warning on line 264 in src/static/helpers/slasHelper.test.ts

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Insert `⏎·····`

Check warning on line 264 in src/static/helpers/slasHelper.test.ts

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Insert `⏎·····`

const authResponse = await slasHelper.authorizeIDP(
mockSlasClient,
parameters
);
const expectedAuthURL =
'https://short_code.api.commercecloud.salesforce.com/shopper/auth/v1/organizations/organization_id/oauth2/authorize?redirect_uri=redirect_uri&response_type=code&client_id=client_id&usid=usid&hint=hint&channel_id=site_id&code_challenge=';
expect(authResponse.url.replace(/code_challenge=[^&]*/, '')).toBe(
expectedAuthURL.replace(/code_challenge=[^&]*/, '')
'https://short_code.api.commercecloud.salesforce.com/shopper/auth/v1/organizations/organization_id/oauth2/authorize?client_id=client_id&channel_id=site_id&hint=hint&redirect_uri=redirect_uri&response_type=code&usid=usid';
expect(authResponse.url.replace(/[&?]code_challenge=[^&]*/, '')).toBe( expectedAuthURL

Check warning on line 272 in src/static/helpers/slasHelper.test.ts

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Insert `⏎`

Check warning on line 272 in src/static/helpers/slasHelper.test.ts

View workflow job for this annotation

GitHub Actions / linux-tests (14)

Insert `⏎`

Check warning on line 272 in src/static/helpers/slasHelper.test.ts

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Insert `⏎`

Check warning on line 272 in src/static/helpers/slasHelper.test.ts

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Insert `⏎`
);
});
});
Expand Down
10 changes: 6 additions & 4 deletions src/static/helpers/slasHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '../../lib/shopperLogin';
import ResponseError from '../responseError';
import TemplateURL from '../templateUrl';
import {BaseUriParameters} from './types';

export const stringToBase64 = isBrowser
? btoa
Expand Down Expand Up @@ -189,6 +190,7 @@ export async function authorizeIDP(
organizationId: string;
clientId: string;
siteId: string;
version?: string;
}>,
parameters: {
redirectURI: string;
Expand All @@ -206,13 +208,13 @@ export async function authorizeIDP(
clientOptions.codeChallenge = await generateCodeChallenge(codeVerifier);
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
// eslint-disable-next-line
const apiPath = ShopperLogin.apiPaths.authorizeCustomer;

const pathParams: ShopperLoginPathParameters = {
const pathParams: ShopperLoginPathParameters & Required<BaseUriParameters> = {
organizationId: slasClient.clientConfig.parameters.organizationId,
shortCode: slasClient.clientConfig.parameters.shortCode,
version: slasClient.clientConfig.parameters.version || 'v1',
};

const queryParams: ShopperLoginQueryParameters = {
client_id: slasClient.clientConfig.parameters.clientId,
channel_id: slasClient.clientConfig.parameters.siteId,
Expand Down

0 comments on commit fc34ee3

Please sign in to comment.