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
3 changes: 3 additions & 0 deletions __tests__/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ const LOGGED_IN_BODY = {
company: null,
experienceLevel: null,
isTeamMember: false,
twitter: null,
github: 'idogithub',
hashnode: null,
bluesky: null,
roadmap: null,
threads: null,
Expand Down
27 changes: 6 additions & 21 deletions __tests__/fixture/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,46 @@ export const usersFixture: DeepPartial<User>[] = [
{
id: '1',
bio: null,
github: 'idogithub',
hashnode: null,
name: 'Ido',
image: 'https://daily.dev/ido.jpg',
email: 'ido@daily.dev',
createdAt: new Date(userCreatedDate),
twitter: null,
username: 'idoshamun',
infoConfirmed: true,
notificationFlags: DEFAULT_NOTIFICATION_SETTINGS,
socialLinks: [
{
platform: 'github',
url: 'https://github.com/idogithub',
},
],
},
{
id: '2',
bio: null,
github: null,
hashnode: null,
name: 'Tsahi',
email: 'tsahi@daily.dev',
image: 'https://daily.dev/tsahi.jpg',
createdAt: new Date(userCreatedDate),
twitter: null,
username: 'tsahidaily',
infoConfirmed: true,
},
{
id: '3',
bio: null,
github: null,
hashnode: null,
name: 'Nimrod',
email: 'nimrod@daily.dev',
image: 'https://daily.dev/nimrod.jpg',
createdAt: new Date(userCreatedDate),
twitter: null,
username: 'nimroddaily',
infoConfirmed: true,
},
{
id: '4',
bio: null,
github: null,
hashnode: null,
name: 'Lee',
image: 'https://daily.dev/lee.jpg',
createdAt: new Date(userCreatedDate),
twitter: null,
username: 'lee',
infoConfirmed: true,
},
Expand All @@ -76,12 +70,9 @@ export const badUsersFixture: DeepPartial<User>[] = [
{
id: 'vordr',
bio: null,
github: null,
hashnode: null,
name: 'Vordr was here',
image: 'https://daily.dev/lee.jpg',
createdAt: new Date(userCreatedDate),
twitter: null,
username: 'vordr',
infoConfirmed: true,
flags: {
Expand All @@ -92,12 +83,9 @@ export const badUsersFixture: DeepPartial<User>[] = [
{
id: 'low-score',
bio: null,
github: null,
hashnode: null,
name: 'Low Score',
image: 'https://daily.dev/lee.jpg',
createdAt: new Date(userCreatedDate),
twitter: null,
username: 'low-score',
infoConfirmed: true,
flags: {
Expand All @@ -108,12 +96,9 @@ export const badUsersFixture: DeepPartial<User>[] = [
{
id: 'low-reputation',
bio: null,
github: null,
hashnode: null,
name: 'Low Reputation',
image: 'https://daily.dev/lee.jpg',
createdAt: new Date(userCreatedDate),
twitter: null,
username: 'low-reputation',
infoConfirmed: true,
reputation: 0,
Expand Down
16 changes: 8 additions & 8 deletions __tests__/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ describe('POST /p/newUser', () => {
image: usersFixture[0].image,
username: usersFixture[0].username,
email: usersFixture[0].email,
github: usersFixture[0].github,
github: 'testgithub',
experienceLevel: 'LESS_THAN_1_YEAR',
})
.expect(200);
Expand All @@ -365,13 +365,13 @@ describe('POST /p/newUser', () => {
const users = await con.getRepository(User).find({ order: { id: 'ASC' } });
expect(users.length).toEqual(3);
expect(users[0].id).toEqual(usersFixture[0].id);
expect(users[0].github).toEqual(usersFixture[0].github);
expect(users[0].github).toEqual('testgithub');
});

it('should ignore GitHub handle if it already exists', async () => {
await con
.getRepository(User)
.save({ ...usersFixture[1], github: usersFixture[0].github });
.save({ ...usersFixture[1], github: 'testgithub' });

const { body } = await request(app.server)
.post('/p/newUser')
Expand All @@ -383,7 +383,7 @@ describe('POST /p/newUser', () => {
image: usersFixture[0].image,
username: usersFixture[0].username,
email: usersFixture[0].email,
github: usersFixture[0].github,
github: 'testgithub',
experienceLevel: 'LESS_THAN_1_YEAR',
})
.expect(200);
Expand All @@ -407,7 +407,7 @@ describe('POST /p/newUser', () => {
image: usersFixture[0].image,
username: usersFixture[0].username,
email: usersFixture[0].email,
twitter: usersFixture[0].twitter,
twitter: 'testtwitter',
experienceLevel: 'LESS_THAN_1_YEAR',
})
.expect(200);
Expand All @@ -416,13 +416,13 @@ describe('POST /p/newUser', () => {

const users = await con.getRepository(User).find({ order: { id: 'ASC' } });
expect(users[0].id).toEqual(usersFixture[0].id);
expect(users[0].twitter).toEqual(usersFixture[0].twitter);
expect(users[0].twitter).toEqual('testtwitter');
});

it('should ignore Twitter handle if it already exists', async () => {
await con
.getRepository(User)
.save({ ...usersFixture[1], twitter: usersFixture[0].twitter });
.save({ ...usersFixture[1], twitter: 'testtwitter' });

const { body } = await request(app.server)
.post('/p/newUser')
Expand All @@ -434,7 +434,7 @@ describe('POST /p/newUser', () => {
image: usersFixture[0].image,
username: usersFixture[0].username,
email: usersFixture[0].email,
twitter: usersFixture[0].twitter,
twitter: 'testtwitter',
experienceLevel: 'LESS_THAN_1_YEAR',
})
.expect(200);
Expand Down
167 changes: 50 additions & 117 deletions __tests__/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,22 @@ beforeEach(async () => {
image: 'https://daily.dev/lee.jpg',
timezone: userTimezone,
username: 'lee',
twitter: 'lee',
github: 'lee',
hashnode: 'lee',
roadmap: 'lee',
threads: 'lee',
codepen: 'lee',
reddit: 'lee',
stackoverflow: '999999/lee',
youtube: 'lee',
linkedin: 'lee',
mastodon: 'https://mastodon.social/@lee',
socialLinks: [
{ platform: 'twitter', url: 'https://twitter.com/lee' },
{ platform: 'github', url: 'https://github.com/lee' },
{ platform: 'hashnode', url: 'https://hashnode.com/@lee' },
{ platform: 'roadmap', url: 'https://roadmap.sh/u/lee' },
{ platform: 'threads', url: 'https://threads.net/@lee' },
{ platform: 'codepen', url: 'https://codepen.io/lee' },
{ platform: 'reddit', url: 'https://reddit.com/u/lee' },
{
platform: 'stackoverflow',
url: 'https://stackoverflow.com/users/999999/lee',
},
{ platform: 'youtube', url: 'https://youtube.com/@lee' },
{ platform: 'linkedin', url: 'https://linkedin.com/in/lee' },
{ platform: 'mastodon', url: 'https://mastodon.social/@lee' },
],
},
]);
await saveFixtures(con, Source, sourcesFixture);
Expand Down Expand Up @@ -1897,6 +1902,40 @@ describe('query user socialLinks', () => {
{ platform: 'twitter', url: 'https://twitter.com/testhandle' },
]);
});

it('should resolve legacy social fields from socialLinks for backwards compatibility', async () => {
await con.getRepository(User).update(
{ id: '1' },
{
socialLinks: [
{ platform: 'github', url: 'https://github.com/testuser' },
{ platform: 'twitter', url: 'https://twitter.com/testhandle' },
{ platform: 'linkedin', url: 'https://linkedin.com/in/testprofile' },
{ platform: 'mastodon', url: 'https://mastodon.social/@testuser' },
{ platform: 'portfolio', url: 'https://example.com' },
],
},
);

const LEGACY_QUERY = `query User($id: ID!) {
user(id: $id) {
id
github
twitter
linkedin
mastodon
portfolio
}
}`;

const res = await client.query(LEGACY_QUERY, { variables: { id: '1' } });
expect(res.errors).toBeFalsy();
expect(res.data.user.github).toBe('testuser');
expect(res.data.user.twitter).toBe('testhandle');
expect(res.data.user.linkedin).toBe('testprofile');
expect(res.data.user.mastodon).toBe('https://mastodon.social/@testuser');
expect(res.data.user.portfolio).toBe('https://example.com');
});
});

describe('query team members', () => {
Expand Down Expand Up @@ -3489,36 +3528,6 @@ describe('mutation updateUserProfile', () => {
'UNAUTHENTICATED',
));

it('should not allow duplicated github', async () => {
loggedUser = '1';

await testMutationErrorCode(
client,
{ mutation: MUTATION, variables: { data: { github: 'lee' } } },
'GRAPHQL_VALIDATION_FAILED',
);
});

it('should not allow duplicated twitter', async () => {
loggedUser = '1';

await testMutationErrorCode(
client,
{ mutation: MUTATION, variables: { data: { twitter: 'lee' } } },
'GRAPHQL_VALIDATION_FAILED',
);
});

it('should not allow duplicated hashnode', async () => {
loggedUser = '1';

await testMutationErrorCode(
client,
{ mutation: MUTATION, variables: { data: { hashnode: 'lee' } } },
'GRAPHQL_VALIDATION_FAILED',
);
});

it('should not allow duplicated username', async () => {
loggedUser = '1';

Expand All @@ -3529,82 +3538,6 @@ describe('mutation updateUserProfile', () => {
);
});

it('should not allow duplicated roadmap', async () => {
loggedUser = '1';

await testMutationErrorCode(
client,
{ mutation: MUTATION, variables: { data: { roadmap: 'lee' } } },
'GRAPHQL_VALIDATION_FAILED',
);
});

it('should not allow duplicated threads', async () => {
loggedUser = '1';

await testMutationErrorCode(
client,
{ mutation: MUTATION, variables: { data: { threads: 'lee' } } },
'GRAPHQL_VALIDATION_FAILED',
);
});

it('should not allow duplicated codepen', async () => {
loggedUser = '1';

await testMutationErrorCode(
client,
{ mutation: MUTATION, variables: { data: { codepen: 'lee' } } },
'GRAPHQL_VALIDATION_FAILED',
);
});

it('should not allow duplicated reddit', async () => {
loggedUser = '1';

await testMutationErrorCode(
client,
{ mutation: MUTATION, variables: { data: { reddit: 'lee' } } },
'GRAPHQL_VALIDATION_FAILED',
);
});

it('should not allow duplicated stackoverflow', async () => {
loggedUser = '1';

await testMutationErrorCode(
client,
{
mutation: MUTATION,
variables: { data: { stackoverflow: '999999/lee' } },
},
'GRAPHQL_VALIDATION_FAILED',
);
});

it('should not allow duplicated linkedin', async () => {
loggedUser = '1';

await testMutationErrorCode(
client,
{ mutation: MUTATION, variables: { data: { linkedin: 'lee' } } },
'GRAPHQL_VALIDATION_FAILED',
);
});

it('should not allow duplicated mastodon', async () => {
loggedUser = '1';

await testMutationErrorCode(
client,
{
mutation: MUTATION,
variables: { data: { mastodon: 'https://mastodon.social/@lee' } },
},
'GRAPHQL_VALIDATION_FAILED',
);
});

it('should not allow empty username', async () => {
loggedUser = '1';

Expand Down
Loading
Loading