Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions plugins/slack-catalog-backend/src/SlackUserProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jest.mock('@slack/web-api', () => {
},
{
id: 'ID_taylor',
enterprise_user: {
id: 'ENTERPRISE_ID_taylor',
},
profile: {
email: 'taylor@seatgeek.com',
image_192: 'taylor-192.png',
Expand Down Expand Up @@ -108,6 +111,76 @@ describe('SlackUserProcessor', () => {
expect(mockSlackClient.users.list).toHaveBeenCalledTimes(1);
});

test('should use enterprise slack user id when present', async () => {
const before: UserEntity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'User',
metadata: {
name: 'taylor',
},
spec: {
profile: { email: 'taylor@seatgeek.com' },
},
};
const result = await processor.postProcessEntity(
before,
{} as any,
() => {},
);

expect(result).toEqual({
apiVersion: 'backstage.io/v1alpha1',
kind: 'User',
metadata: {
name: 'taylor',
annotations: {
'slack.com/user_id': 'ENTERPRISE_ID_taylor',
},
},
spec: {
profile: {
email: 'taylor@seatgeek.com',
picture: 'taylor-192.png',
},
},
});
});

test('should fall back to top-level slack user id when enterprise_user is missing', async () => {
const before: UserEntity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'User',
metadata: {
name: 'rufus',
},
spec: {
profile: { email: 'rufus@seatgeek.com' },
},
};
const result = await processor.postProcessEntity(
before,
{} as any,
() => {},
);

expect(result).toEqual({
apiVersion: 'backstage.io/v1alpha1',
kind: 'User',
metadata: {
name: 'rufus',
annotations: {
'slack.com/user_id': 'ID_rufus',
},
},
spec: {
profile: {
email: 'rufus@seatgeek.com',
picture: 'rufus-192.png',
},
},
});
});

test('should no op if not a user', async () => {
const before: SystemEntity = {
apiVersion: 'backstage.io/v1alpha1',
Expand Down
5 changes: 3 additions & 2 deletions plugins/slack-catalog-backend/src/SlackUserProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ export class SlackUserProcessor implements CatalogProcessor {
entity.spec.profile = {};
}

if (slackUser.id) {
entity.metadata.annotations['slack.com/user_id'] = slackUser.id;
const slackUserId = slackUser.enterprise_user?.id ?? slackUser.id;
if (slackUserId) {
entity.metadata.annotations['slack.com/user_id'] = slackUserId;
}
// if the user entity doesn't already have a profile picture set, *and* there's a slack avatar for the user, add that.
if (!entity.spec.profile.picture && slackUser.profile?.image_192) {
Expand Down
Loading