Skip to content

Commit b71ff89

Browse files
committed
Pass userId in from URL
1 parent ff270e9 commit b71ff89

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

lib/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Republic, { route } from 'republic/next'
22
import { LoadUserProfile } from './user/'
33

44
export default new Republic(
5-
route.page('/', 'users#profile', async () => {
6-
return await LoadUserProfile({ id: 'guid' })
5+
route.page('/:userId', 'users#profile', async ({ params }) => {
6+
return await LoadUserProfile({ userId: params.userId })
77
})
88
)

lib/user/LoadUserProfile.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as FakeUserGateway from './FakeUserGateway'
44
describe('LoadUserProfile', () => {
55
describe('when loading profile by id', () => {
66
test('user has name', async () => {
7-
const { user } = await LoadUserProfile(FakeUserGateway, { id: 'guid' })
7+
const { user } = await LoadUserProfile(FakeUserGateway, { userId: 'guid' })
88
expect(user.name).toBe('Mr Luke Fake')
99
})
1010
})

lib/user/LoadUserProfile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import UserGateway from './UserGateway'
22

33
type Request = {
4-
id: string
4+
userId: string
55
}
66

77
type Response = {
@@ -11,6 +11,6 @@ type Response = {
1111
}
1212

1313
export default async function LoadUserProfile (gateway: UserGateway, req: Request) : Promise<Response> {
14-
const user = await gateway.findById(req.id)
14+
const user = await gateway.findById(req.userId)
1515
return { user }
1616
}

pages/users/profile.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import mockExecute from '../../test/support/mockExecute'
44
import UserProfile from './profile'
55

66
describe('UserProfile', () => {
7+
const userId = 'uniq-guid'
78
const fakeUser = { basicInfo: { name: 'Luke', email: '[email protected]' } }
89

910
describe('when user views the page', () => {
1011
test('user can see user name', async () => {
11-
mockExecute('findUserById', { userId: 'guid' }).reply(200, fakeUser)
12-
const page = await mountPage(UserProfile, 'users#profile')
13-
expect(page).toIncludeText('Luke')
12+
mockExecute('findUserById', { userId }).reply(200, fakeUser)
13+
const page = await mountPage(UserProfile, 'users#profile', { userId })
14+
expect(page).toIncludeText(fakeUser.basicInfo.name)
1415
})
1516
})
1617
})

0 commit comments

Comments
 (0)