Skip to content

Commit cd659b2

Browse files
authored
Merge pull request #6 from Typeform/fix-release
Fixes for release
2 parents f6d3d49 + c6b9fac commit cd659b2

18 files changed

+966
-552
lines changed

.eslintrc.json

-13
This file was deleted.

.prettierrc.json

-4
This file was deleted.

package.json

+14-13
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,32 @@
2929
"isomorphic-fetch": "^2.2.1"
3030
},
3131
"devDependencies": {
32-
"@babel/cli": "^7.0.0-beta.44",
33-
"@babel/core": "^7.0.0-beta.44",
34-
"@babel/node": "^7.0.0-beta.44",
35-
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.44",
36-
"@babel/preset-env": "^7.0.0-beta.44",
32+
"@babel/cli": "^7.0.0-rc.1",
33+
"@babel/core": "^7.0.0-rc.1",
34+
"@babel/node": "^7.0.0-rc.1",
35+
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-rc.1",
36+
"@babel/preset-env": "^7.0.0-rc.1",
3737
"@commitlint/cli": "^6.1.3",
3838
"@commitlint/config-conventional": "^6.1.3",
39-
"axios-mock-adapter": "^1.15.0",
4039
"babel-core": "^7.0.0-bridge.0",
4140
"babel-eslint": "^8.2.3",
4241
"babel-jest": "^22.4.3",
4342
"babel-loader": "^7.1.4",
44-
"eslint": "^4.19.1",
45-
"eslint-config-prettier": "^2.9.0",
46-
"eslint-plugin-prettier": "^2.6.0",
4743
"husky": "^0.14.3",
4844
"in-publish": "^2.0.0",
4945
"jest": "^22.4.3",
5046
"jest-fetch-mock": "^1.6.5",
5147
"json-server": "^0.14.0",
5248
"lint-staged": "^7.0.4",
5349
"nodemon": "^1.18.3",
54-
"prettier": "^1.12.1",
5550
"semantic-release": "^15.1.7",
56-
"sinon": "^4.5.0",
51+
"standard": "^11.0.1",
5752
"webpack": "^4.6.0",
5853
"webpack-cli": "^2.0.14"
5954
},
6055
"lint-staged": {
6156
"*.js": [
62-
"eslint",
57+
"standard",
6358
"git add"
6459
]
6560
},
@@ -78,10 +73,16 @@
7873
"build:dist": "webpack --mode production",
7974
"build:lib": "NODE_ENV=production babel src --out-dir lib",
8075
"prepublish": "in-publish && npm run build:dist && npm run build:lib || not-in-publish",
81-
"pretty": "prettier './{src,tests}/**/*.js' --write",
76+
"lint": "standard ./src",
8277
"semantic-release": "semantic-release",
8378
"server": "node ./tests/integration/mockServer.js",
8479
"server:dev": "nodemon ./tests/integration/mockServer.js"
8580
},
81+
"standard": {
82+
"env": [
83+
"jest"
84+
],
85+
"globals": ["fetch"]
86+
},
8687
"peerDependencies": {}
8788
}

src/create-client.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
1+
/* globals fetch */
12
import 'isomorphic-fetch'
23
import { API_BASE_URL } from './constants'
34

45
export const clientConstructor = ({ token, ...options }) => {
56
return {
67
request: (args) => {
7-
88
const {
99
url,
10+
data,
11+
headers: argsHeaders = {},
1012
...otherArgs
1113
} = args
1214

15+
const {
16+
headers = {}
17+
} = options
18+
1319
const requestParameters = {
1420
...options,
1521
...otherArgs
1622
}
1723

1824
return fetch(`${API_BASE_URL}${url}`, {
25+
...requestParameters,
26+
body: JSON.stringify(data),
1927
headers: {
28+
...headers,
29+
...argsHeaders,
2030
Authorization: `bearer ${token}`
21-
},
22-
...requestParameters
31+
}
2332
})
2433
.then(response => response.json())
25-
// .catch(error => { throw `${error}` })
34+
.catch(error => { throw new Error(error) })
2635
}
2736
}
2837
}

src/forms.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ export default http => ({
1010
}
1111
})
1212

13-
const getForms = (http, { page, page_size, search } = {}) => {
13+
const getForms = (http, { page, pageSize, search } = {}) => {
1414
return http.request({
1515
method: 'get',
1616
url: `/forms`,
1717
page,
18-
page_size,
18+
page_size: pageSize,
1919
search
2020
})
2121
}

src/images.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ export default http => ({
44
add: args => addImage(http, args),
55
delete: args => deleteImage(http, args)
66
})
7-
export const getImages = http => {
7+
const getImages = http => {
88
return http.request({
99
method: 'get',
1010
url: '/images'
1111
})
1212
}
1313

14-
export const getImage = (
14+
const getImage = (
1515
http,
1616
{ id, returns, size, backgroundSize, choiceSize }
1717
) => {
@@ -21,7 +21,7 @@ export const getImage = (
2121
}
2222

2323
if (returns === 'json') {
24-
requestQuery['headers'] = {
24+
requestQuery.headers = {
2525
Accept: 'application/json'
2626
}
2727
}
@@ -30,15 +30,15 @@ export const getImage = (
3030
if (['default', 'thumbnail', 'mobile'].includes(size)) {
3131
requestQuery['url'] += `/image/${size}`
3232
} else {
33-
throw `Image size doesn't exists`
33+
throw new Error(`Image size doesn't exists`)
3434
}
3535
}
3636

3737
if (backgroundSize !== undefined) {
3838
if (['default', 'thumbnail', 'mobile', 'tablet'].includes(backgroundSize)) {
3939
requestQuery['url'] += `/background/${backgroundSize}`
4040
} else {
41-
throw `Image background size doesn't exists`
41+
throw new Error(`Image background size doesn't exists`)
4242
}
4343
}
4444

@@ -54,26 +54,26 @@ export const getImage = (
5454
if (choiceImageSizes.includes(choiceSize)) {
5555
requestQuery['url'] += `/choice/${choiceSize}`
5656
} else {
57-
throw `Image choice size doesn't exists`
57+
throw new Error(`Image choice size doesn't exists`)
5858
}
5959
}
6060

6161
return http.request(requestQuery)
6262
}
6363

64-
export const addImage = (http, { image, media_type, file_name }) => {
64+
const addImage = (http, { image, mediaType, fileName }) => {
6565
return http.request({
6666
method: 'post',
6767
url: `/images`,
6868
data: {
6969
image,
70-
file_name,
71-
media_type
70+
file_name: fileName,
71+
media_type: mediaType
7272
}
7373
})
7474
}
7575

76-
export const deleteImage = (http, { id }) => {
76+
const deleteImage = (http, { id }) => {
7777
return http.request({
7878
method: 'delete',
7979
url: `/images/${id}`

src/responses.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export default http => ({
22
list: args => getResponses(http, args)
33
})
44

5-
export const getResponses = (
5+
const getResponses = (
66
http,
77
{
88
uid,

src/teams.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ export default http => {
1414
}
1515
}
1616

17-
export const getTeam = http => {
17+
const getTeam = http => {
1818
return http.request({
1919
method: 'get',
2020
url: '/teams/mine'
2121
})
2222
}
2323

24-
export const addMembers = (http, { members }) => {
24+
const addMembers = (http, { members }) => {
2525
if (!isMemberPropValid(members)) {
2626
throw `No member provided`
2727
}
@@ -39,7 +39,7 @@ export const addMembers = (http, { members }) => {
3939
})
4040
}
4141

42-
export const removeMembers = (http, { members }) => {
42+
const removeMembers = (http, { members }) => {
4343
if (!isMemberPropValid(members)) {
4444
throw `No member provided`
4545
}

src/themes.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default http => ({
88
update: args => updateTheme(http, args)
99
})
1010

11-
export const getThemes = (http, { page, page_size } = {}) => {
11+
const getThemes = (http, { page, page_size } = {}) => {
1212
return http.request({
1313
method: 'get',
1414
url: '/themes',
@@ -19,14 +19,14 @@ export const getThemes = (http, { page, page_size } = {}) => {
1919
})
2020
}
2121

22-
export const getTheme = (http, { id }) => {
22+
const getTheme = (http, { id }) => {
2323
return http.request({
2424
method: 'get',
2525
url: `/themes/${id}`
2626
})
2727
}
2828

29-
export const createTheme = (
29+
const createTheme = (
3030
http,
3131
{ background, colors, font, has_transparent_button, name }
3232
) => {
@@ -50,14 +50,14 @@ export const createTheme = (
5050
})
5151
}
5252

53-
export const deleteTheme = (http, { id }) => {
53+
const deleteTheme = (http, { id }) => {
5454
return http.request({
5555
method: 'delete',
5656
url: `/themes/${id}`
5757
})
5858
}
5959

60-
export const updateTheme = (
60+
const updateTheme = (
6161
http,
6262
{ id, background, colors, font, has_transparent_button, name }
6363
) => {

src/typeform.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import webhooks from './webhooks'
99

1010
export const createClient = (args = {}) => {
1111
if (args.token === undefined) {
12-
throw 'Token is missing'
12+
throw new Error('Token is missing')
1313
}
1414

1515
const http = clientConstructor(args)

src/webhooks.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ const createOrUpdateWebhook = (
3232
{ uid, tag, url, enable = false }
3333
) => {
3434
if (url === undefined) {
35-
throw `Please provide an url for ${tag}`
35+
throw new Error(`Please provide an url for ${tag}`)
3636
}
3737
if (tag === undefined) {
38-
throw `Please provide a tag name for the webhook`
38+
throw new Error(`Please provide a tag name for the webhook`)
3939
}
4040
return http.request({
4141
method: 'put',

tests/unit/create-client.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { clientConstructor } from '../../src/create-client'
2+
import { API_BASE_URL } from '../../src/constants'
3+
4+
beforeEach(() => {
5+
fetch.resetMocks()
6+
fetch.mockResponse(JSON.stringify({}))
7+
})
8+
9+
const client = clientConstructor({
10+
token: 'abc'
11+
})
12+
13+
test('request pass correct headers', () => {
14+
client.request({
15+
url: '/forms',
16+
headers: {
17+
Accepts: 'application/json'
18+
}
19+
})
20+
21+
expect(fetch.mock.calls[0][0]).toBe(`${API_BASE_URL}/forms`)
22+
expect(fetch.mock.calls[0][1].headers).toEqual({
23+
Accepts: 'application/json',
24+
Authorization: 'bearer abc'
25+
})
26+
})

tests/unit/forms.test.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,26 @@ test('getForm sets get method', () => {
3030

3131
test('updateForm sends the correct UID and data', () => {
3232
formsRequest.update({
33-
uid: 'abc123', data: {
33+
uid: 'abc123',
34+
data: {
3435
title: 'hola'
3536
}
3637
})
38+
const bodyParsed = JSON.parse(fetch.mock.calls[0][1].body)
3739
expect(fetch.mock.calls[0][0]).toBe(`${API_BASE_URL}/forms/abc123`)
38-
expect(fetch.mock.calls[0][1].data.title).toBe('hola')
40+
expect(bodyParsed.title).toBe('hola')
3941
})
4042

4143
test('updateForm sets patch method in request by default', () => {
4244
formsRequest.update({
43-
uid: 'abc123', data: {
45+
uid: 'abc123',
46+
data: {
4447
title: 'hola'
4548
}
4649
})
4750
expect(fetch.mock.calls[0][1].method).toBe('patch')
4851
})
4952

50-
5153
test('updateForm sets put method in request when override option is set', () => {
5254
formsRequest.update({
5355
uid: 'abc123',

tests/unit/images.test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ test('get images by ID', () => {
2626
test('adding an image pass the required values', () => {
2727
imagesRequest.add({
2828
image: 'bGRqZmxzZGpmbHNoZmtoc2RrZmpoc2tqZA==',
29-
media_type: 'image/gif',
30-
file_name: 'newimage.gif'
29+
mediaType: 'image/gif',
30+
fileName: 'newimage.gif'
3131
})
3232

3333
expect(fetch.mock.calls[0][0]).toBe(`${API_BASE_URL}/images`)
3434
expect(fetch.mock.calls[0][1].method).toBe('post')
3535

36-
const imageData = fetch.mock.calls[0][1].data
37-
expect(imageData).toEqual({
36+
const imageData = fetch.mock.calls[0][1].body
37+
expect(imageData).toEqual(JSON.stringify({
3838
image: 'bGRqZmxzZGpmbHNoZmtoc2RrZmpoc2tqZA==',
39-
media_type: 'image/gif',
40-
file_name: 'newimage.gif'
41-
})
39+
file_name: 'newimage.gif',
40+
media_type: 'image/gif'
41+
}))
4242
})
4343

4444
test('deleting an image sets the correct method and id', () => {

0 commit comments

Comments
 (0)