Skip to content

Commit 2162345

Browse files
feat: update user info (#3288)
1 parent 0cef5ac commit 2162345

File tree

8 files changed

+1112
-4
lines changed

8 files changed

+1112
-4
lines changed

__tests__/boot.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
UserMarketingCta,
3737
UserNotification,
3838
} from '../src/entity';
39+
import { DatasetLocation } from '../src/entity/dataset/DatasetLocation';
3940
import {
4041
OrganizationMemberRole,
4142
SourceMemberRoles,
@@ -142,6 +143,7 @@ const LOGGED_IN_BODY = {
142143
youtube: null,
143144
linkedin: null,
144145
mastodon: null,
146+
readme: null,
145147
language: undefined,
146148
isPlus: false,
147149
defaultFeedId: null,
@@ -155,6 +157,7 @@ const LOGGED_IN_BODY = {
155157
coresRole: CoresRole.None,
156158
clickbaitTries: null,
157159
hasLocationSet: false,
160+
location: null,
158161
},
159162
marketingCta: null,
160163
feeds: [],
@@ -413,6 +416,48 @@ describe('logged in boot', () => {
413416
expect(res.body.user.hasLocationSet).toBe(true);
414417
});
415418

419+
it('should return location when user has locationId set', async () => {
420+
const location = await con.getRepository(DatasetLocation).save({
421+
country: 'United States',
422+
city: 'San Francisco',
423+
subdivision: 'California',
424+
iso2: 'US',
425+
iso3: 'USA',
426+
timezone: 'America/Los_Angeles',
427+
ranking: 1,
428+
});
429+
430+
await con.getRepository(User).save({
431+
...usersFixture[0],
432+
locationId: location.id,
433+
});
434+
435+
mockLoggedIn();
436+
const res = await request(app.server)
437+
.get(BASE_PATH)
438+
.set('User-Agent', TEST_UA)
439+
.set('Cookie', 'ory_kratos_session=value;')
440+
.expect(200);
441+
442+
expect(res.body.user.location).toEqual({
443+
id: location.id,
444+
city: 'San Francisco',
445+
subdivision: 'California',
446+
country: 'United States',
447+
});
448+
});
449+
450+
it('should return null location when user has no locationId', async () => {
451+
mockLoggedIn();
452+
const res = await request(app.server)
453+
.get(BASE_PATH)
454+
.set('User-Agent', TEST_UA)
455+
.set('Cookie', 'ory_kratos_session=value;')
456+
.expect(200);
457+
458+
expect(res.body.user.location).toBeNull();
459+
});
460+
416461
it('should set kratos cookie expiration', async () => {
417462
mockLoggedIn();
418463
const kratosCookie = 'ory_kratos_session';
@@ -1683,6 +1728,8 @@ describe('funnel boot', () => {
16831728
'subscriptionFlags',
16841729
'clickbaitTries',
16851730
'hasLocationSet',
1731+
'location',
1732+
'readme',
16861733
]),
16871734
});
16881735
});

0 commit comments

Comments
 (0)