Skip to content

Commit

Permalink
refactoring slack auth variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
SpencerKaiser committed Jan 10, 2024
1 parent cadcbeb commit d674c6f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 22 deletions.
6 changes: 5 additions & 1 deletion packages/api/src/api/auth/callback/slack/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export type SlackTokenData = {

export const get = async (req: Request, res: Response) => {
const myCode: string = req.query[codeQueryParam] as string;
const { slackClientID, slackClientSecret, slackBotToken } = slackAuth;
const {
clientId: slackClientID,
clientSecret: slackClientSecret,
botToken: slackBotToken,
} = slackAuth;

const returnTo = req.query[Config.global.authReturnUriParamName] as string | undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const slackAuthBaseUrl: string =
export const formatSlackAuthUrl: AuthUrlFormatter = ({ returnTo }) => {
const queryArgs = new URLSearchParams({
redirect_uri: formatRedirectUri({ returnTo }),
client_id: slackAuth.slackClientID,
client_id: slackAuth.clientId,
}).toString();

return `${slackAuthBaseUrl}${queryArgs}`;
Expand Down
11 changes: 4 additions & 7 deletions packages/api/src/env/auth/slackAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import setEnv from '@americanairlines/simple-env';

export const slackAuth = setEnv({
required: {
slackBotToken: 'SLACK_BOT_TOKEN',
slackSigningSecret: 'SLACK_SIGNING_SECRET',
slackClientID: 'SLACK_CLIENT_ID',
slackClientSecret: 'SLACK_CLIENT_SECRET',
},
optional: {
slackLogLevel: 'SLACK_LOG_LEVEL',
botToken: 'SLACK_BOT_TOKEN',
signingSecret: 'SLACK_SIGNING_SECRET',
clientId: 'SLACK_CLIENT_ID',
clientSecret: 'SLACK_CLIENT_SECRET',
},
});
5 changes: 0 additions & 5 deletions packages/api/src/env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,3 @@ config(); // Must be called before exports
* All core environment variables
*/
export * from './env';

/**
* All auth environment variables
*/
export * as Auth from './auth';
12 changes: 6 additions & 6 deletions packages/api/tests/api/auth/callback/slack/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jest.mock('../../../../../src/api/auth/utils/formatRedirectUri');
jest.mock('../../../../../src/env/auth');

(slackAuth as Partial<typeof slackAuth>) = {
slackClientID: 'mockClientID',
slackBotToken: 'mockBotToken',
slackClientSecret: 'mockClientSecret',
clientId: 'mockClientID',
botToken: 'mockBotToken',
clientSecret: 'mockClientSecret',
};

const mockToken = {
Expand Down Expand Up @@ -53,12 +53,12 @@ describe('Slack auth callback', () => {

await get(mockReq as any, {} as any);

expect(webClientSpy).toBeCalledWith(slackAuth.slackBotToken);
expect(webClientSpy).toBeCalledWith(slackAuth.botToken);
expect(mockTokenMethod).toHaveBeenCalledTimes(1);
expect(mockTokenMethod).toHaveBeenCalledWith(
expect.objectContaining({
client_id: slackAuth.slackClientID,
client_secret: slackAuth.slackClientSecret,
client_id: slackAuth.clientId,
client_secret: slackAuth.clientSecret,
code: mockReq.query.code,
redirect_uri: mockRedirectUri,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jest.mock('../../../../../../../src/api/auth/utils/formatRedirectUri');
const formatRedirectUriMock = getMock(formatRedirectUri);

(slackAuth as Partial<typeof slackAuth>) = {
slackClientID: 'mockClientId',
clientId: 'mockClientId',
};

describe('formatSlackAuthUrl', () => {
Expand All @@ -26,7 +26,7 @@ describe('formatSlackAuthUrl', () => {
expect(formatRedirectUriMock).toBeCalledWith({ returnTo });

expect(redirectUri).toEqual(
`${slackAuthBaseUrl}redirect_uri=${mockRedirectUri}&client_id=${slackAuth.slackClientID}`,
`${slackAuthBaseUrl}redirect_uri=${mockRedirectUri}&client_id=${slackAuth.clientId}`,
);
});
});

0 comments on commit d674c6f

Please sign in to comment.