Skip to content
Open
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__/__snapshots__/users.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Array [
exports[`mutation updateUserProfile should update user profile 1`] = `
Object {
"bio": null,
"cover": null,
"createdAt": Any<String>,
"experienceLevel": null,
"github": null,
Expand All @@ -51,6 +52,8 @@ Object {
"language": null,
"name": "Ido",
"permalink": "http://localhost:5002/aaa1",
"readme": null,
"readmeHtml": "",
"timezone": "Europe/London",
"twitter": null,
"username": "aaa1",
Expand Down
46 changes: 46 additions & 0 deletions __tests__/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
UserMarketingCta,
UserNotification,
} from '../src/entity';
import { DatasetLocation } from '../src/entity/dataset/DatasetLocation';
import {
OrganizationMemberRole,
SourceMemberRoles,
Expand Down Expand Up @@ -141,6 +142,7 @@ const LOGGED_IN_BODY = {
youtube: null,
linkedin: null,
mastodon: null,
readme: null,
language: undefined,
isPlus: false,
defaultFeedId: null,
Expand All @@ -154,6 +156,7 @@ const LOGGED_IN_BODY = {
coresRole: CoresRole.None,
clickbaitTries: null,
hasLocationSet: false,
location: undefined,
},
marketingCta: null,
feeds: [],
Expand Down Expand Up @@ -412,6 +415,48 @@ describe('logged in boot', () => {
expect(res.body.user.hasLocationSet).toBe(true);
});

it('should return location when user has locationId set', async () => {
const location = await con.getRepository(DatasetLocation).save({
country: 'United States',
city: 'San Francisco',
subdivision: 'California',
iso2: 'US',
iso3: 'USA',
timezone: 'America/Los_Angeles',
ranking: 1,
});

await con.getRepository(User).save({
...usersFixture[0],
locationId: location.id,
});

mockLoggedIn();
const res = await request(app.server)
.get(BASE_PATH)
.set('User-Agent', TEST_UA)
.set('Cookie', 'ory_kratos_session=value;')
.expect(200);

expect(res.body.user.location).toEqual({
id: location.id,
city: 'San Francisco',
subdivision: 'California',
country: 'United States',
});
});

it('should return undefined location when user has no locationId', async () => {
mockLoggedIn();
const res = await request(app.server)
.get(BASE_PATH)
.set('User-Agent', TEST_UA)
.set('Cookie', 'ory_kratos_session=value;')
.expect(200);

expect(res.body.user.location).toBeUndefined();
});

it('should set kratos cookie expiration', async () => {
mockLoggedIn();
const kratosCookie = 'ory_kratos_session';
Expand Down Expand Up @@ -1682,6 +1727,7 @@ describe('funnel boot', () => {
'subscriptionFlags',
'clickbaitTries',
'hasLocationSet',
'location',
]),
});
});
Expand Down
64 changes: 0 additions & 64 deletions __tests__/keywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { postsFixture } from './fixture/post';
import { DataSource } from 'typeorm';
import createOrGetConnection from '../src/db';
import { updateFlagsStatement } from '../src/common';
import { keywordsFixture } from './fixture/keywords';

let con: DataSource;
let state: GraphQLTestingState;
Expand Down Expand Up @@ -433,66 +432,3 @@ describe('keywords flags field', () => {
expect(keyword?.flags).toEqual({});
});
});

describe('query autocompleteKeywords', () => {
const QUERY = /* GraphQL */ `
query AutocompleteKeywords($query: String!, $limit: Int) {
autocompleteKeywords(query: $query, limit: $limit) {
keyword
title
}
}
`;

beforeEach(async () => {
await saveFixtures(con, Keyword, keywordsFixture);
});

it('should return autocomplete allowed keywords when not logged in', async () => {
const res = await client.query(QUERY, {
variables: {
query: 'dev',
},
});
expect(res.errors).toBeFalsy();
expect(res.data.autocompleteKeywords).toEqual(
expect.arrayContaining([
{ keyword: 'webdev', title: 'Web Development' },
{ keyword: 'development', title: null },
]),
);
});

it('should return autocomplete results', async () => {
loggedUser = '1';

const res = await client.query(QUERY, {
variables: {
query: 'dev',
},
});
expect(res.errors).toBeFalsy();
expect(res.data.autocompleteKeywords).toEqual(
expect.arrayContaining([
{ keyword: 'webdev', title: 'Web Development' },
{ keyword: 'web-development', title: null },
{ keyword: 'development', title: null },
]),
);
});

it('should limit autocomplete results', async () => {
loggedUser = '1';

const res = await client.query(QUERY, {
variables: {
query: 'dev',
limit: 1,
},
});
expect(res.errors).toBeFalsy();
expect(res.data.autocompleteKeywords).toEqual([
{ keyword: 'development', title: null },
]);
});
});
Loading