-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ULMS-1442 Changed eslint configuration
- Loading branch information
Showing
31 changed files
with
20,293 additions
and
4,750 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,22 @@ | ||
{ | ||
"env":{ | ||
"env": { | ||
"test": { | ||
"plugins": ["@babel/plugin-transform-modules-commonjs"] | ||
}, | ||
"es": { | ||
"presets": [ | ||
["@babel/preset-env", { | ||
"modules": false, | ||
"targets": "last 2 versions" | ||
}] | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"modules": false, | ||
"targets": "last 2 versions" | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
"babel-plugin-annotate-pure-calls" | ||
] | ||
"plugins": ["babel-plugin-annotate-pure-calls"] | ||
}, | ||
"lib": { | ||
"presets": ["@babel/preset-env"] | ||
}, | ||
"rollup": { | ||
"presets": [ | ||
["@babel/preset-env", { | ||
"modules": false | ||
}] | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
{ | ||
"extends": "standard", | ||
"env": { | ||
"jest": true | ||
} | ||
}, | ||
"extends": [ | ||
"airbnb-base", | ||
"plugin:promise/recommended", | ||
"plugin:sonarjs/recommended", | ||
"plugin:unicorn/recommended", | ||
"prettier" | ||
], | ||
"plugins": ["promise", "sonarjs", "unicorn"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [16.13.1] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: npm ci | ||
- run: npm run lint | ||
test: | ||
needs: lint | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [16.13.1] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: npm ci | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v16.13.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/es/ | ||
/lib/ | ||
|
||
# Node modules directory | ||
/node_modules/ | ||
|
||
# Tests output | ||
/coverage/ | ||
|
||
# Optional eslint cache | ||
.eslintcache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "semi": false, "singleQuote": true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# ulms-api-clients-js | ||
|
||
JavaScript API clients for ULMS platform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,132 @@ | ||
import { BasicClient } from '../src/basic-client' | ||
import BasicClient from '../src/basic-client' | ||
|
||
const baseUrl = 'https://test.url' | ||
const httpClient = { | ||
get: jest.fn(), | ||
put: jest.fn(), | ||
post: jest.fn(), | ||
patch: jest.fn(), | ||
delete: jest.fn() | ||
delete: jest.fn(), | ||
} | ||
const tokenProvider = { | ||
getToken: jest.fn().mockImplementation(() => 'token') | ||
getToken: jest.fn().mockImplementation(() => 'token'), | ||
} | ||
|
||
const headersWithoutLabels = { authorization: 'Bearer token', 'content-type': 'application/json' } | ||
const headersWithoutLabels = { | ||
authorization: 'Bearer token', | ||
'content-type': 'application/json', | ||
} | ||
|
||
const Client = new BasicClient(baseUrl, httpClient, tokenProvider) | ||
|
||
const labels = { | ||
app_audience: 'audience', | ||
app_label: 'label', | ||
app_version: 'version', | ||
scope: 'scope' | ||
scope: 'scope', | ||
} | ||
|
||
const ulmsLabels = { | ||
'ulms-app-audience': 'audience', | ||
'ulms-app-label': 'label', | ||
'ulms-app-version': 'version', | ||
'ulms-scope': 'scope' | ||
'ulms-scope': 'scope', | ||
} | ||
|
||
const urlGeneratorCases = [ | ||
['objectParams', { a: 0, b: 1, c: 2 }, '?a=0&b=1&c=2'], | ||
['advancedObjectParams', { a: 'a', b: [1, 2, 3], c: { cc: 3, dd: 4 } }, '?a=a&b[]=1&b[]=2&b[]=3&c[cc]=3&c[dd]=4'], | ||
[ | ||
'advancedObjectParams', | ||
{ a: 'a', b: [1, 2, 3], c: { cc: 3, dd: 4 } }, | ||
'?a=a&b[]=1&b[]=2&b[]=3&c[cc]=3&c[dd]=4', | ||
], | ||
['objectParamsUndefined', { a: undefined }, ''], | ||
['arrayParams', ['a', 'b', 'c'], '?0=a&1=b&2=c'], | ||
['advancedArrayParams', { alphabet: ['a', 'b', 'c'] }, '?alphabet[]=a&alphabet[]=b&alphabet[]=c'], | ||
['withoutParams', undefined, ''] | ||
[ | ||
'advancedArrayParams', | ||
{ alphabet: ['a', 'b', 'c'] }, | ||
'?alphabet[]=a&alphabet[]=b&alphabet[]=c', | ||
], | ||
['withoutParams', undefined, ''], | ||
] | ||
|
||
const methodsWithoutDataCases = [ | ||
['get'], | ||
['delete'] | ||
] | ||
const methodsWithoutDataCases = [['get'], ['delete']] | ||
|
||
const methodsWithDataCases = [ | ||
['post', 'data'], | ||
['put', 'data'], | ||
['patch', 'data'] | ||
['patch', 'data'], | ||
] | ||
describe('Basic client suite', () => { | ||
it.each(urlGeneratorCases)('URL generator should work with: endpoint — %s and %j as params', (endpoint, params, expectedParams) => { | ||
const resultUrl = Client._url(`/${endpoint}`, params) | ||
expect(resultUrl).toBe(`${baseUrl}/${endpoint}${expectedParams}`) | ||
}) | ||
it.each(urlGeneratorCases)( | ||
'URL generator should work with: endpoint — %s and %j as params', | ||
(endpoint, parameters, expectedParameters) => { | ||
const resultUrl = Client.url(`/${endpoint}`, parameters) | ||
expect(resultUrl).toBe(`${baseUrl}/${endpoint}${expectedParameters}`) | ||
} | ||
) | ||
|
||
it('Headers should compare with labels', () => { | ||
const resultHeaders = BasicClient._headers('token', { label: 'a' }) | ||
const resultHeaders = BasicClient.headers('token', { label: 'a' }) | ||
expect(resultHeaders.authorization).toBe('Bearer token') | ||
expect(resultHeaders['content-type']).toBe('application/json') | ||
expect(resultHeaders.label).toBe('a') | ||
}) | ||
|
||
it('Headers should compare without labels', () => { | ||
const resultHeaders = BasicClient._headers('token') | ||
const resultHeaders = BasicClient.headers('token') | ||
expect(resultHeaders).toEqual(headersWithoutLabels) | ||
}) | ||
|
||
it('Labes should set and destroy', () => { | ||
it('Labels should set and destroy', () => { | ||
Client.setLabels(labels) | ||
expect(Client._labels).toEqual(ulmsLabels) | ||
|
||
Client.clearLabels() | ||
expect(Client._labels).toEqual({}) | ||
}) | ||
|
||
it.each(methodsWithoutDataCases)('%s method should work (without labels)', async (method) => { | ||
await Client['_' + method](baseUrl) | ||
expect(httpClient[method]).toBeCalledWith(baseUrl, { headers: headersWithoutLabels }) | ||
}) | ||
expect(Client.labels).toEqual(ulmsLabels) | ||
|
||
it.each(methodsWithoutDataCases)('%s method should work (with labels)', async (method) => { | ||
Client.setLabels(labels) | ||
await Client['_' + method](baseUrl) | ||
Client.clearLabels() | ||
expect(httpClient[method]).toBeCalledWith(baseUrl, { headers: { ...headersWithoutLabels, ...ulmsLabels } }) | ||
}) | ||
|
||
it.each(methodsWithDataCases)('%s method should work (without labels) with payload: %s', async (method, data) => { | ||
await Client['_' + method](baseUrl, data) | ||
expect(httpClient[method]).toBeCalledWith(baseUrl, data, { headers: headersWithoutLabels }) | ||
expect(Client.labels).toEqual({}) | ||
}) | ||
|
||
it.each(methodsWithDataCases)('%s method should work (with labels) with payload: %s', async (method, data) => { | ||
Client.setLabels(labels) | ||
await Client['_' + method](baseUrl, data) | ||
Client.clearLabels() | ||
expect(httpClient[method]).toBeCalledWith(baseUrl, data, { headers: { ...headersWithoutLabels, ...ulmsLabels } }) | ||
}) | ||
it.each(methodsWithoutDataCases)( | ||
'%s method should work (without labels)', | ||
async (method) => { | ||
await Client[method](baseUrl) | ||
expect(httpClient[method]).toBeCalledWith(baseUrl, { | ||
headers: headersWithoutLabels, | ||
}) | ||
} | ||
) | ||
|
||
it.each(methodsWithoutDataCases)( | ||
'%s method should work (with labels)', | ||
async (method) => { | ||
Client.setLabels(labels) | ||
await Client[method](baseUrl) | ||
Client.clearLabels() | ||
expect(httpClient[method]).toBeCalledWith(baseUrl, { | ||
headers: { ...headersWithoutLabels, ...ulmsLabels }, | ||
}) | ||
} | ||
) | ||
|
||
it.each(methodsWithDataCases)( | ||
'%s method should work (without labels) with payload: %s', | ||
async (method, data) => { | ||
await Client[method](baseUrl, data) | ||
expect(httpClient[method]).toBeCalledWith(baseUrl, data, { | ||
headers: headersWithoutLabels, | ||
}) | ||
} | ||
) | ||
|
||
it.each(methodsWithDataCases)( | ||
'%s method should work (with labels) with payload: %s', | ||
async (method, data) => { | ||
Client.setLabels(labels) | ||
await Client[method](baseUrl, data) | ||
Client.clearLabels() | ||
expect(httpClient[method]).toBeCalledWith(baseUrl, data, { | ||
headers: { ...headersWithoutLabels, ...ulmsLabels }, | ||
}) | ||
} | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.