Skip to content

Commit ff270e9

Browse files
committed
Update swagger endpoint with more fields
1 parent 688a3d6 commit ff270e9

File tree

10 files changed

+50
-18
lines changed

10 files changed

+50
-18
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
**/*.js
22
.next
33
node_modules
4-
api/mock

api/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.swagger-codegen*
2+
swagger.json
3+
mock
4+
README.md

api/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
all: install start
22

33
install:
4+
swagger-codegen generate -i swagger.yml -l swagger
45
swagger-codegen generate -i swagger.yml -l nodejs-server -o mock
56

67
start:

api/swagger.yml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,43 @@ paths:
3131
schema:
3232
$ref: "#/definitions/Error"
3333
definitions:
34-
User:
35-
required:
36-
- name
37-
- email
34+
UserBasicInfo:
3835
properties:
3936
name:
4037
type: string
4138
example: "Mr Bob Example"
42-
email:
39+
biography:
40+
type: string
41+
example: "I like bicycles"
42+
twitter:
43+
type: string
44+
example: "@bobexample"
45+
createdAt:
4346
type: string
44-
example: "[email protected]"
47+
format: date-time
48+
lastSeenAt:
49+
type: string
50+
format: date-time
51+
52+
User:
53+
properties:
54+
basicInfo:
55+
$ref: "#/definitions/UserBasicInfo"
56+
friends:
57+
type: array
58+
items:
59+
$ref: "#/definitions/UserBasicInfo"
60+
example:
61+
- name: James
62+
biography: Like Bond
63+
createdAt: 2017-11-12T22:27:35.278Z
64+
lastSeenAt: 2017-11-12T22:27:35.278Z
65+
- name: Dan
66+
biography: Yeah mayne
67+
twitter: "@danmayne"
68+
createdAt: 2017-11-12T22:27:35.278Z
69+
lastSeenAt: 2017-11-12T22:27:35.278Z
70+
4571
Error:
4672
required:
4773
- message

components/User/components/Profile.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import Profile from './Profile'
44

55
describe('<Profile />', () => {
66
it('should display name', () => {
7-
expect(shallow(<Profile name='Luke' />)).toIncludeText('Luke')
7+
expect(shallow(<Profile name='Luke' />)).toIncludeText('Name: Luke')
88
})
99
})

lib/api/Client.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import * as Swagger from 'swagger-client'
2-
import * as fs from 'fs'
3-
import * as jsYaml from 'js-yaml'
2+
import * as spec from '../../api/swagger.json'
43

54
const API_HOST = process.env.API_HOST
65

76
export function loadSpec (): any {
8-
const spec = fs.readFileSync(__dirname + '/../../api/swagger.yml', 'utf8')
9-
return { ...jsYaml.safeLoad(spec), host: API_HOST }
7+
return { ...spec, host: API_HOST }
108
}
119

1210
export async function execute (operationId: String, parameters: any): Promise<any> {

lib/user/HTTPUserGateway.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import * as HTTPUserGateway from './HTTPUserGateway'
22
import mockExecute from '../../test/support/mockExecute'
33

44
describe('HTTPUserGateway', () => {
5+
const fakeUser = { basicInfo: { name: 'Jim', email: '[email protected]' } }
6+
57
describe('when finding by id', () => {
68
test('user has name', async () => {
7-
mockExecute('findUserById', { userId: 'guid' }).reply(200, { name: 'Jim', email: '[email protected]' })
9+
mockExecute('findUserById', { userId: 'guid' }).reply(200, fakeUser)
810
const user = await HTTPUserGateway.findById('guid')
911
expect(user.name).toBe('Jim')
1012
expect(user.email).toBe('[email protected]')

lib/user/HTTPUserGateway.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import User from './User'
44
const API_ORIGIN = process.env.API_ORIGIN
55

66
export async function findById (userId: string) : Promise<User> {
7-
const { name, email } = await execute('findUserById', { userId })
7+
const user = await execute('findUserById', { userId })
8+
const { name, email } = user.basicInfo
89
return new User(name, email)
910
}

lib/user/LoadUserProfile.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ type Response = {
1111
}
1212

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

pages/users/profile.test.tsx

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

66
describe('UserProfile', () => {
7+
const fakeUser = { basicInfo: { name: 'Luke', email: '[email protected]' } }
8+
79
describe('when user views the page', () => {
810
test('user can see user name', async () => {
9-
mockExecute('findUserById', { userId: 'guid' }).reply(200, { name: 'Luke' })
11+
mockExecute('findUserById', { userId: 'guid' }).reply(200, fakeUser)
1012
const page = await mountPage(UserProfile, 'users#profile')
1113
expect(page).toIncludeText('Luke')
1214
})

0 commit comments

Comments
 (0)