Skip to content
Merged
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
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
extends: ['airbnb-base', 'prettier'],
plugins: ['prettier'],
rules: {
'prettier/prettier': 'error',
'arrow-body-style': ['error', 'as-needed'],
'no-param-reassign': 'off',
'no-console': ['error', { allow: ['error'] }],
},
env: {
es6: true,
jest: true,
browser: true,
},
};
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "all"
}
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ node_js:
- "current"
script:
- npm run coveralls
before_script:
- yarn run lint
36 changes: 18 additions & 18 deletions __tests__/api.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fetchFromApi } from '../lib/api';
import fetchFromApi from '../lib/api';

describe('fetchFromApi', () => {
beforeEach(() => {
Expand All @@ -8,66 +8,66 @@ describe('fetchFromApi', () => {
it('should resolve fetch and return data with error', async () => {
fetch.mockResolvedValue({
status: 400,
message: 'The name is empty'
message: 'The name is empty',
});

const requestData = {
method: 'POST',
body: { name: '' }
body: { name: '' },
};
try {
await fetchFromApi('http://localhost:3000/products', requestData);
} catch (e) {
expect(e).toEqual({
status: 400,
message: 'The name is empty'
message: 'The name is empty',
});
}
});

it('should resolve fetch and return data', async () => {
fetch.mockResolvedValue({
data: [{ name: 'Xbox' }]
data: [{ name: 'Xbox' }],
});

const response = await fetchFromApi('http://localhost:3000/products');

expect(response).toEqual({
data: [{ name: 'Xbox' }]
data: [{ name: 'Xbox' }],
});
});

it('should define application/json as default headers', async () => {
fetch.mockResolvedValue({
data: [{ name: 'Xbox' }]
data: [{ name: 'Xbox' }],
});
let requestData = {};
const requestData = {};

const response = await fetchFromApi('http://localhost:3000/products', requestData);
await fetchFromApi('http://localhost:3000/products', requestData);

expect(requestData).toEqual({
headers: {
'content-type': 'application/json'
}
'content-type': 'application/json',
},
});
});

it('should not overwrite content type if specified in requestData', async () => {
fetch.mockResolvedValue({
data: [{ name: 'Xbox' }]
data: [{ name: 'Xbox' }],
});
let requestData = {
const requestData = {
headers: {
'content-type': 'application/x-www-form-urlencoded'
}
'content-type': 'application/x-www-form-urlencoded',
},
};

const response = await fetchFromApi('http://localhost:3000/products', requestData);
await fetchFromApi('http://localhost:3000/products', requestData);

expect(requestData).toEqual({
headers: {
'content-type': 'application/x-www-form-urlencoded'
}
'content-type': 'application/x-www-form-urlencoded',
},
});
});

Expand Down
Loading