-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/resource builder #2
Changes from 15 commits
208892d
0d4a72a
4b85dc5
3abd164
4867997
3f43fc8
af54843
fbafb07
74c6dd7
e6b69da
040c4a6
b01ebee
d3154fd
3741ea9
1e57d17
f57fa75
c9ea94d
6df0c7d
096bc51
00c099e
f9950ec
55a9c43
de5883a
8d9e9b3
ac97b95
e913e86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"presets": [ | ||
"env", | ||
"flow" | ||
], | ||
"plugins": [ | ||
"transform-runtime", | ||
"transform-object-rest-spread" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Javascript Node CircleCI 2.0 configuration file | ||
# | ||
# Check https://circleci.com/docs/2.0/language-javascript/ for more details | ||
# | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
# specify the version you desire here | ||
- image: circleci/node:7.10 | ||
|
||
# Specify service dependencies here if necessary | ||
# CircleCI maintains a library of pre-built images | ||
# documented at https://circleci.com/docs/2.0/circleci-images/ | ||
# - image: circleci/mongo:3.4.4 | ||
|
||
working_directory: ~/repo | ||
|
||
steps: | ||
- checkout | ||
|
||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "package.json" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-dependencies- | ||
|
||
- run: yarn install | ||
|
||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v1-dependencies-{{ checksum "package.json" }} | ||
|
||
# run tests! | ||
- run: | ||
name: Jest Suite | ||
command: yarn jest tests --ci --testResultsProcessor="jest-junit" | ||
environment: | ||
JEST_JUNIT_OUTPUT: "reports/junit/js-test-results.xml" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
{ | ||
"extends": "airbnb-base" | ||
"parser": "babel-eslint", | ||
"extends": "airbnb-base", | ||
"env": { | ||
"browser": true, | ||
"jest": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[ignore] | ||
|
||
[include] | ||
|
||
[libs] | ||
|
||
[lints] | ||
|
||
[options] | ||
|
||
[strict] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Jsonapi Orchestrator | ||
|
||
Building better jsonapi-compliant code | ||
|
||
[![BCH compliance](https://bettercodehub.com/edge/badge/MyJobGlasses/jsonapi-orchestrator?branch=master)](https://bettercodehub.com/) | ||
|
||
[![CircleCI](https://circleci.com/gh/MyJobGlasses/jsonapi-orchestrator.svg?style=svg)](https://circleci.com/gh/MyJobGlasses/jsonapi-orchestrator) | ||
|
||
# HOW TO | ||
|
||
[See examples in the /examples folder](./examples/) | ||
|
||
# TODO | ||
[draft] | ||
- think to add fetch polyfill | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
let mainConnector = null; | ||
|
||
/** | ||
* @todo handle if we want to overwrite mainConnector | ||
*/ | ||
export default class JsonApiConnector { | ||
constructor(params) { | ||
this.url = params.url; | ||
mainConnector = mainConnector || this; | ||
} | ||
|
||
static connector() { | ||
if (!mainConnector) { | ||
return new JsonApiConnector(); | ||
} | ||
return mainConnector; | ||
} | ||
|
||
buildEndpoint(path) { | ||
return `${this.url}/${path}`; | ||
} | ||
} | ||
|
||
export const getMainConnector = JsonApiConnector.connector; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To delete ? Replaced by Api ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aaaah merde j'avais zappé ce truc là on avait parlé de connecteur a un moment mais je sais plus ce qu'on voulait y mettre dedans... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import JsonapiRequestBuilder from '../../builders/JsonapiRequestBuilder'; | ||
import JsonapiResourceReader from '../../builders/JsonapiResourceReader'; | ||
import JsonapiResourceWriter from '../../builders/JsonapiResourceWriter'; | ||
|
||
describe('JsonapiRequestBuilder', () => { | ||
let requestBuilder; | ||
let resource; | ||
|
||
describe('constructor', () => { | ||
test('can assign requestBuilder variables during instanciation', () => { | ||
resource = new JsonapiResourceReader(); | ||
const requestBuilderArguments = { | ||
path: '/foo/bar', | ||
httpMethod: 'OPTIONS', | ||
resource, | ||
params: { id: '42' }, | ||
}; | ||
requestBuilder = new JsonapiRequestBuilder(requestBuilderArguments); | ||
expect(requestBuilder.path).toEqual('/foo/bar'); | ||
expect(requestBuilder.httpMethod).toEqual('OPTIONS'); | ||
expect(requestBuilder.resource).toEqual(resource); | ||
expect(requestBuilder.params).toEqual(expect.objectContaining({ id: '42' })); | ||
}); | ||
}); | ||
|
||
describe('instance methods', () => { | ||
describe('#addMeta', () => { | ||
beforeEach( () => { | ||
requestBuilder = new JsonapiRequestBuilder({}); | ||
}); | ||
|
||
test('merges new meta', () => { | ||
requestBuilder.addMeta({ invitationToken: '42' }); | ||
requestBuilder.addMeta({ token: 'deadbeef' }); | ||
|
||
expect(requestBuilder.meta).toMatchObject({ | ||
invitationToken: '42', | ||
token: 'deadbeef', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#action', () => { | ||
describe('building a read request', () => { | ||
beforeEach(() => { | ||
resource = new JsonapiResourceReader({ | ||
jsonapiType: 'conversation', params: { id: 'cafebabe' }, | ||
}); | ||
requestBuilder = new JsonapiRequestBuilder({ | ||
resource, method: 'OPTIONS', path: '/conversations', | ||
}); | ||
}); | ||
|
||
test('returns a correct read action', () => { | ||
expect(requestBuilder.action()).toMatchObject({ | ||
type: 'READ_CONVERSATION_RESOURCE', | ||
// params: { id: 'cafebabe' }, | ||
meta: {}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('building a write request', () => { | ||
beforeEach(() => { | ||
const conversationResource = new JsonapiResourceWriter({ | ||
jsonapiType: 'conversation', | ||
params: { userid: 'cafebabe' }, | ||
attributes: { | ||
recipient: 'deadbeef', | ||
}, | ||
}); | ||
const messageResource = new JsonapiResourceWriter({ | ||
jsonapiType: 'message', | ||
attributes: { | ||
text: 'Hello world !', | ||
clientId: '0ff1ce', | ||
}, | ||
}); | ||
conversationResource.sidepost('messages', [messageResource]); | ||
requestBuilder = new JsonapiRequestBuilder({ | ||
resource: conversationResource, path: '/conversations', | ||
}); | ||
}); | ||
|
||
test('returns a correct write action', () => { | ||
expect(requestBuilder.action()).toMatchObject({ | ||
type: 'CREATE_CONVERSATION_RESOURCE', | ||
params: { userid: 'cafebabe' }, | ||
data: { | ||
type: 'conversation', | ||
attributes: { recipient: 'deadbeef' }, | ||
relationships: { | ||
messages: { | ||
data: [{ | ||
type: 'message', | ||
method: 'create', | ||
'temp-id': expect.any(String), | ||
}], | ||
}, | ||
}, | ||
}, | ||
included: [{ | ||
type: 'message', | ||
'temp-id': expect.any(String), | ||
attributes: { | ||
text: 'Hello world !', | ||
clientId: '0ff1ce', | ||
}, | ||
}], | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je ne pense pas que ce soit necessaire, je pense qu'il faut plus préciser à l'utilisateur de le faire lui même s'il veut que ça fonctionne.
Raison : Si le dev a déjà installé le polyfill, on risque d'alourdir inutilement le package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c'est ton code à toi que j'avais repris ça lol