Skip to content

Commit

Permalink
Merge branch 'main' into AS-463-vordr-posts
Browse files Browse the repository at this point in the history
  • Loading branch information
omBratteng authored Aug 13, 2024
2 parents 629216b + c6466de commit c94f146
Show file tree
Hide file tree
Showing 21 changed files with 408 additions and 101 deletions.
8 changes: 6 additions & 2 deletions __tests__/common/mailing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { saveFixtures } from '../helpers';
import createOrGetConnection from '../../src/db';
import { User } from '../../src/entity';
import { usersFixture } from '../fixture/user';
import { CioUnsubscribeTopic, syncSubscription } from '../../src/common';
import {
CioUnsubscribeTopic,
ghostUser,
syncSubscription,
} from '../../src/common';

let con: DataSource;

Expand Down Expand Up @@ -48,7 +52,7 @@ describe('mailing', () => {

const users = await con.getRepository(User).find({
where: {
id: Not('404'),
id: Not(ghostUser.id),
},
});

Expand Down
10 changes: 10 additions & 0 deletions __tests__/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ describe('slack integration', () => {

expect(res.errors).toBeFalsy();
expect(slackPostMessage).toHaveBeenCalledTimes(1);
expect(slackPostMessage).toHaveBeenCalledWith({
channel: '1',
text: `Ido connected the \"<http://localhost:5002/squads/squadslack?utm_source=notification&utm_medium=slack&utm_campaign=connected&jt=squadslacktoken1&source=squadslack&type=squad|Squad Slack>\" Squad to this channel. Important updates from this Squad will be posted here 🙌`,
unfurl_links: false,
});
});

it('should update channel for source', async () => {
Expand Down Expand Up @@ -328,6 +333,11 @@ describe('slack integration', () => {
});

expect(slackPostMessage).toHaveBeenCalledTimes(2);
expect(slackPostMessage).toHaveBeenNthCalledWith(2, {
channel: '2',
text: `Ido connected the \"<http://localhost:5002/squads/squadslack?utm_source=notification&utm_medium=slack&utm_campaign=connected&jt=squadslacktoken1&source=squadslack&type=squad|Squad Slack>\" Squad to this channel. Important updates from this Squad will be posted here 🙌`,
unfurl_links: false,
});
});

it('should not allow connecting source if existing connection is already present', async () => {
Expand Down
32 changes: 32 additions & 0 deletions __tests__/integrations/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ import {
UserIntegrationType,
} from '../../src/entity/UserIntegration';
import { SlackEvent } from '../../src/common';
import {
AnalyticsEventName,
sendAnalyticsEvent,
} from '../../src/integrations/analytics';

jest.mock('../../src/integrations/analytics', () => ({
...(jest.requireActual('../../src/integrations/analytics') as Record<
string,
unknown
>),
sendAnalyticsEvent: jest.fn(),
}));

let app: FastifyInstance;
let con: DataSource;
Expand Down Expand Up @@ -159,6 +171,16 @@ describe('GET /integrations/slack/auth/callback', () => {
slackUserId: 'su1',
},
});
expect(sendAnalyticsEvent).toHaveBeenCalledTimes(1);
expect(sendAnalyticsEvent).toHaveBeenCalledWith([
{
event_name: AnalyticsEventName.ConfirmAddingWorkspace,
user_id: '1',
app_platform: 'api',
event_timestamp: expect.any(Date),
target_id: UserIntegrationType.Slack,
},
]);
});

it('should update integration if it already exists', async () => {
Expand Down Expand Up @@ -218,6 +240,16 @@ describe('GET /integrations/slack/auth/callback', () => {
slackUserId: 'su1',
},
});
expect(sendAnalyticsEvent).toHaveBeenCalledTimes(1);
expect(sendAnalyticsEvent).toHaveBeenCalledWith([
{
event_name: AnalyticsEventName.ConfirmAddingWorkspace,
user_id: '1',
app_platform: 'api',
event_timestamp: expect.any(Date),
target_id: UserIntegrationType.Slack,
},
]);
});
});

Expand Down
119 changes: 119 additions & 0 deletions __tests__/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ArticlePost, Keyword, Source, User, UserPost } from '../src/entity';
import { postsFixture } from './fixture/post';
import { sourcesFixture } from './fixture/source';
import { usersFixture } from './fixture/user';
import { ghostUser, updateFlagsStatement } from '../src/common';

let con: DataSource;
let state: GraphQLTestingState;
Expand Down Expand Up @@ -528,3 +529,121 @@ describe('query searchSourceSuggestions', () => {
]);
});
});

describe('query searchUserSuggestions', () => {
const QUERY = (query: string): string => `{
searchUserSuggestions(query: "${query}") {
query
hits {
id
title
subtitle
image
}
}
}
`;

beforeEach(async () => {
await saveFixtures(con, User, usersFixture);
});

it('should return search suggestions', async () => {
const res = await client.query(QUERY('i'));
expect(res.errors).toBeFalsy();
expect(res.data.searchUserSuggestions).toBeTruthy();

const result = res.data.searchUserSuggestions;

expect(result.query).toBe('i');
expect(result.hits).toHaveLength(3);
expect(result.hits).toMatchObject([
{
id: '1',
image: 'https://daily.dev/ido.jpg',
subtitle: 'idoshamun',
title: 'Ido',
},
{
id: '2',
image: 'https://daily.dev/tsahi.jpg',
subtitle: 'tsahidaily',
title: 'Tsahi',
},
{
id: '3',
image: 'https://daily.dev/nimrod.jpg',
subtitle: 'nimroddaily',
title: 'Nimrod',
},
]);
});

it('should only return infoConfirmed users', async () => {
await con.getRepository(User).update({ id: '3' }, { infoConfirmed: false });
const res = await client.query(QUERY('i'));
expect(res.data.searchUserSuggestions).toBeTruthy();

const result = res.data.searchUserSuggestions;

expect(result.query).toBe('i');
expect(result.hits).toHaveLength(2);
expect(result.hits).toMatchObject([
{
id: '1',
image: 'https://daily.dev/ido.jpg',
subtitle: 'idoshamun',
title: 'Ido',
},
{
id: '2',
image: 'https://daily.dev/tsahi.jpg',
subtitle: 'tsahidaily',
title: 'Tsahi',
},
]);
});

it('should only return vodr false users', async () => {
await con.getRepository(User).update(
{ id: '3' },
{
flags: updateFlagsStatement<User>({
vordr: true,
}),
},
);
const res = await client.query(QUERY('i'));
expect(res.data.searchUserSuggestions).toBeTruthy();

const result = res.data.searchUserSuggestions;

expect(result.query).toBe('i');
expect(result.hits).toHaveLength(2);
expect(result.hits).toMatchObject([
{
id: '1',
image: 'https://daily.dev/ido.jpg',
subtitle: 'idoshamun',
title: 'Ido',
},
{
id: '2',
image: 'https://daily.dev/tsahi.jpg',
subtitle: 'tsahidaily',
title: 'Tsahi',
},
]);
});

it('should not return 404 user', async () => {
await saveFixtures(con, User, [ghostUser]);
const res = await client.query(QUERY('ghost'));
expect(res.data.searchUserSuggestions).toBeTruthy();

const result = res.data.searchUserSuggestions;

expect(result.query).toBe('ghost');
expect(result.hits).toHaveLength(0);
});
});
41 changes: 5 additions & 36 deletions __tests__/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
stackoverflowSocialUrlMatch,
threadsSocialUrlMatch,
twitterSocialUrlMatch,
ghostUser,
} from '../src/common';
import { DataSource, In, IsNull } from 'typeorm';
import createOrGetConnection from '../src/db';
Expand Down Expand Up @@ -2536,15 +2537,7 @@ describe('mutation deleteUser', () => {
it('should delete user from database', async () => {
loggedUser = '1';

await con.getRepository(User).save([
{
id: '404',
name: 'Not found',
image: 'https://daily.dev/404.jpg',
timezone: 'utc',
createdAt: new Date(),
},
]);
await con.getRepository(User).save([ghostUser]);

await client.mutate(MUTATION);

Expand All @@ -2558,15 +2551,7 @@ describe('mutation deleteUser', () => {
it('should delete author ID from post', async () => {
loggedUser = '1';

await con.getRepository(User).save([
{
id: '404',
name: 'Not found',
image: 'https://daily.dev/404.jpg',
timezone: 'utc',
createdAt: new Date(),
},
]);
await con.getRepository(User).save([ghostUser]);

await client.mutate(MUTATION);

Expand All @@ -2577,15 +2562,7 @@ describe('mutation deleteUser', () => {
it('should delete scout ID from post', async () => {
loggedUser = '1';

await con.getRepository(User).save([
{
id: '404',
name: 'Not found',
image: 'https://daily.dev/404.jpg',
timezone: 'utc',
createdAt: new Date(),
},
]);
await con.getRepository(User).save([ghostUser]);

await client.mutate(MUTATION);

Expand Down Expand Up @@ -2615,15 +2592,7 @@ describe('DELETE /v1/users/me', () => {
const BASE_PATH = '/v1/users/me';

beforeEach(async () => {
await con.getRepository(User).save([
{
id: '404',
name: 'Not found',
image: 'https://daily.dev/404.jpg',
timezone: 'utc',
createdAt: new Date(),
},
]);
await con.getRepository(User).save([ghostUser]);
});

it('should not authorize when not logged in', async () => {
Expand Down
28 changes: 14 additions & 14 deletions __tests__/workers/postAddedSlackChannelSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ describe('postAddedSlackChannelSend worker', () => {
channel: '1',
attachments: [
{
author_icon: 'https://app.daily.dev/apple-touch-icon.png',
author_name: 'daily.dev',
author_icon: 'http://image.com/a',
author_name: 'A | daily.dev',
image_url: 'https://daily.dev/image.jpg',
title: 'P1',
title_link:
'http://localhost:5002/posts/p1?utm_source=notification&utm_medium=slack&utm_campaign=new_post',
},
],
text: 'New post on "A" source. <http://localhost:5002/posts/p1?utm_source=notification&utm_medium=slack&utm_campaign=new_post|http://localhost:5002/posts/p1>',
text: 'New post: <http://localhost:5002/posts/p1?utm_source=notification&utm_medium=slack&utm_campaign=new_post|http://localhost:5002/posts/p1>',
unfurl_links: false,
});
});
Expand Down Expand Up @@ -191,15 +191,15 @@ describe('postAddedSlackChannelSend worker', () => {
channel: '1',
attachments: [
{
author_icon: 'https://app.daily.dev/apple-touch-icon.png',
author_name: 'daily.dev',
author_icon: 'http//image.com/squadslackchannel',
author_name: 'Squad Slack Channel | daily.dev',
image_url: 'https://daily.dev/image.jpg',
title: 'Squad Channel Post 1',
title_link:
'http://localhost:5002/posts/squadslackchannelp1?jt=squadslackchanneltoken1&source=squadslackchannel&type=squad&utm_source=notification&utm_medium=slack&utm_campaign=new_post',
'http://localhost:5002/posts/squadslackchannelp1?utm_source=notification&utm_medium=slack&utm_campaign=new_post&jt=squadslackchanneltoken1&source=squadslackchannel&type=squad',
},
],
text: 'New post on "Squad Slack Channel" Squad. <http://localhost:5002/posts/squadslackchannelp1?jt=squadslackchanneltoken1&source=squadslackchannel&type=squad&utm_source=notification&utm_medium=slack&utm_campaign=new_post|http://localhost:5002/posts/squadslackchannelp1>',
text: 'New post: <http://localhost:5002/posts/squadslackchannelp1?utm_source=notification&utm_medium=slack&utm_campaign=new_post&jt=squadslackchanneltoken1&source=squadslackchannel&type=squad|http://localhost:5002/posts/squadslackchannelp1>',
unfurl_links: false,
});
});
Expand Down Expand Up @@ -242,15 +242,15 @@ describe('postAddedSlackChannelSend worker', () => {
channel: '1',
attachments: [
{
author_icon: 'https://app.daily.dev/apple-touch-icon.png',
author_name: 'daily.dev',
author_icon: 'http//image.com/squadslackchannel',
author_name: 'Squad Slack Channel | daily.dev',
image_url: 'https://daily.dev/image.jpg',
title: 'Squad Channel Post 1',
title_link:
'http://localhost:5002/posts/squadslackchannelp1?utm_source=notification&utm_medium=slack&utm_campaign=new_post',
},
],
text: 'New post on "Squad Slack Channel" Squad. <http://localhost:5002/posts/squadslackchannelp1?utm_source=notification&utm_medium=slack&utm_campaign=new_post|http://localhost:5002/posts/squadslackchannelp1>',
text: 'New post: <http://localhost:5002/posts/squadslackchannelp1?utm_source=notification&utm_medium=slack&utm_campaign=new_post|http://localhost:5002/posts/squadslackchannelp1>',
unfurl_links: false,
});
});
Expand Down Expand Up @@ -309,15 +309,15 @@ describe('postAddedSlackChannelSend worker', () => {
channel: '1',
attachments: [
{
author_icon: 'https://app.daily.dev/apple-touch-icon.png',
author_name: 'daily.dev',
author_icon: 'http//image.com/squadslackchannel',
author_name: 'Squad Slack Channel | daily.dev',
image_url: 'https://daily.dev/image.jpg',
title: 'Squad Channel Post 1',
title_link:
'http://localhost:5002/posts/squadslackchannelp1?jt=squadslackchanneltoken1&source=squadslackchannel&type=squad&utm_source=notification&utm_medium=slack&utm_campaign=new_post',
'http://localhost:5002/posts/squadslackchannelp1?utm_source=notification&utm_medium=slack&utm_campaign=new_post&jt=squadslackchanneltoken1&source=squadslackchannel&type=squad',
},
],
text: 'Ido shared a new post on "Squad Slack Channel" Squad. <http://localhost:5002/posts/squadslackchannelp1?jt=squadslackchanneltoken1&source=squadslackchannel&type=squad&utm_source=notification&utm_medium=slack&utm_campaign=new_post|http://localhost:5002/posts/squadslackchannelp1>',
text: 'Ido shared a new post: <http://localhost:5002/posts/squadslackchannelp1?utm_source=notification&utm_medium=slack&utm_campaign=new_post&jt=squadslackchanneltoken1&source=squadslackchannel&type=squad|http://localhost:5002/posts/squadslackchannelp1>',
unfurl_links: false,
});
});
Expand Down
Loading

0 comments on commit c94f146

Please sign in to comment.