Skip to content
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

#223 => Step 12 : Fixes and normalizing packages names #251

Closed
wants to merge 8 commits into from
Closed
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
7 changes: 0 additions & 7 deletions packages/client-rest-tt-body/__tests__/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/client-rest-tt-body/src/index.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/client-rest-tt-cookies/__tests__/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/client-rest-tt-cookies/src/index.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/client-rest-tt-headers/__tests__/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/client-rest-tt-headers/src/index.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/client-rest-tt-manager/__tests__/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/client-rest-tt-manager/src/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/client-token-storage-local-storage/src/index.ts

This file was deleted.

8 changes: 4 additions & 4 deletions packages/client/__tests__/accounts-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const userStorage = {
}

const defaultResponse = {
json: async () => defaultResponse
content: true
}

const transport = {
Expand Down Expand Up @@ -106,19 +106,19 @@ describe('AccountsClient', () => {
describe('handleResponse', () => {

it('should return the body of the response',async () => {
const response = { json: () => ({ content: true }) }
const response = { content: true }
client.handleResponse(response)
expect((await client.handleResponse(response)).content).toBe(true)
})

it('should return the error if the response contains one',async () => {
const response = { json: () => ({ error: 'error' }) }
const response = { error: 'error' }
client.handleResponse(response)
expect((await client.handleResponse(response))).toBe('error')
})

it('should set the user if the response contains one',async () => {
const response = { json: () => ({ user: 'user' }) }
const response = { user: 'user' }
await client.handleResponse(response)
expect(userStorage.setUser).toBeCalledWith('user')
})
Expand Down
5 changes: 2 additions & 3 deletions packages/client/src/accounts-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ export default class AccountsClient {
}

public async handleResponse(response: any): Promise<any> {
const res = await response.json();
const { error, user } = res
const { error, user } = response
if(error) {
return error;
}
if(user) {
this.userStorage.setUser(user)
}
return res
return response
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@accounts/cts-local-storage",
"name": "@accounts/cts-localstorage",
"version": "0.1.0-beta.10",
"description": "Accounts-JS Client Token Storage Local Storage",
"main": "lib/index.js",
Expand Down Expand Up @@ -29,7 +29,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/accounts-js/accounts/tree/master/packages/cts-local-storage"
"url": "https://github.com/accounts-js/accounts/tree/master/packages/cts-localstorage"
},
"keywords": [
"accounts",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tokens } from "@accounts/types";

export default class CTSLocalStorage {
export default class ClientTokenStorageLocalStorage {

public setAccessToken(accessToken?: string): void {
if(this.checkToken(accessToken)){
Expand Down
1 change: 1 addition & 0 deletions packages/cts-localstorage/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './cts-localstorage';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ClientRestTTBody from '../src';
import CTTRestBody from '../src';

const defaultClientRestTTBody = new ClientRestTTBody();
const defaultCTTRestBody = new CTTRestBody();

const denyClientRestTTBody = new ClientRestTTBody({
const denyCTTRestBody = new CTTRestBody({
access: {
canStore: false
},
Expand All @@ -24,84 +24,84 @@ const responseNoTokens = {
json: () => ({})
};

describe('ClientRestTTBody', () => {
describe('CTTRestBody', () => {

describe('constructor', () => {

it('should provide default configuration', () => {
expect(defaultClientRestTTBody.accessConfig).toBeDefined()
expect(defaultCTTRestBody.accessConfig).toBeDefined()
})

})

describe('setAccessToken', () => {

it('should set accessToken', () => {
expect(defaultClientRestTTBody.setAccessToken({}, {}, accessToken)).toEqual([ {}, { accessToken } ])
expect(defaultCTTRestBody.setAccessToken({}, {}, accessToken)).toEqual([ {}, { accessToken } ])
})

it('should not set accessToken if canStore is false', () => {
expect(denyClientRestTTBody.setAccessToken({}, {}, accessToken)).toEqual([ {}, {} ])
expect(denyCTTRestBody.setAccessToken({}, {}, accessToken)).toEqual([ {}, {} ])
})

})

describe('setRefreshToken', () => {

it('should set refreshToken', () => {
expect(defaultClientRestTTBody.setRefreshToken({}, {}, refreshToken)).toEqual([ {}, { refreshToken } ])
expect(defaultCTTRestBody.setRefreshToken({}, {}, refreshToken)).toEqual([ {}, { refreshToken } ])
})

it('should not set refreshToken if canStore is false', () => {
expect(denyClientRestTTBody.setRefreshToken({}, {}, refreshToken)).toEqual([ {}, {} ])
expect(denyCTTRestBody.setRefreshToken({}, {}, refreshToken)).toEqual([ {}, {} ])
})

})

describe('setTokens', () => {

it('should set both Tokens', () => {
expect(defaultClientRestTTBody.setTokens({},{},tokens)).toEqual([ {}, tokens ])
expect(defaultCTTRestBody.setTokens({},{},tokens)).toEqual([ {}, tokens ])
})

})

describe('getAccessToken', () => {

it('should get accessToken', () => {
expect(defaultClientRestTTBody.getAccessToken(response)).resolves.toBe(accessToken)
expect(defaultCTTRestBody.getAccessToken(response)).resolves.toBe(accessToken)
})

it('should return undefined if no accessToken in body', () => {
expect(defaultClientRestTTBody.getAccessToken(response, {})).resolves.toBe(undefined)
expect(defaultCTTRestBody.getAccessToken(response, {})).resolves.toBe(undefined)
})

it('should return undefined if no accessToken in response body', () => {
expect(defaultClientRestTTBody.getAccessToken(responseNoTokens)).resolves.toBe(undefined)
expect(defaultCTTRestBody.getAccessToken(responseNoTokens)).resolves.toBe(undefined)
})

})

describe('getRefreshToken', () => {

it('should get refreshToken from response body', () => {
expect(defaultClientRestTTBody.getRefreshToken(response)).resolves.toBe(refreshToken)
expect(defaultCTTRestBody.getRefreshToken(response)).resolves.toBe(refreshToken)
})

it('should return undefined if no refreshToken in body', () => {
expect(defaultClientRestTTBody.getRefreshToken(response, {})).resolves.toBe(undefined)
expect(defaultCTTRestBody.getRefreshToken(response, {})).resolves.toBe(undefined)
})

it('should return undefined if no refreshToken in response body', () => {
expect(defaultClientRestTTBody.getRefreshToken(responseNoTokens)).resolves.toBe(undefined)
expect(defaultCTTRestBody.getRefreshToken(responseNoTokens)).resolves.toBe(undefined)
})

})

describe('getTokens', () => {

it('should get both Tokens', () => {
expect(defaultClientRestTTBody.getTokens(response)).resolves.toEqual(tokens)
expect(defaultCTTRestBody.getTokens(response)).resolves.toEqual(tokens)
})

})
Expand Down
7 changes: 7 additions & 0 deletions packages/ctt-rest-body/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import CTTRestBody from '../src';

describe('CTTRestBody entry', () => {
it('should have default export CTTRestBody', () => {
expect(typeof CTTRestBody).toBe('function');
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@accounts/client-rest-tt-body",
"name": "@accounts/ctt-rest-body",
"version": "0.1.0-beta.10",
"description": "Accounts-JS Client Rest Transport Token Body",
"description": "Accounts-JS Client Transport Token Rest Body",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"publishConfig": {
Expand Down Expand Up @@ -29,7 +29,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/accounts-js/accounts/tree/master/packages/client-rest-tt-body"
"url": "https://github.com/accounts-js/accounts/tree/master/packages/ctt-rest-body"
},
"keywords": [
"accounts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const defaultConfig: Configuration<TokenConfiguration> = {
}
}

export default class ClientRestTTBody {
export default class ClientTokenTransportRestBody {

private accessConfig: TokenConfiguration;
private refreshConfig: TokenConfiguration;
Expand Down
1 change: 1 addition & 0 deletions packages/ctt-rest-body/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './ctt-rest-body';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ClientRestTTCookies from '../src';
import CTTRestCookies from '../src';

const defaultClientRestTTCookies = new ClientRestTTCookies();
const defaultCTTRestCookies = new CTTRestCookies();

const denyClientRestTTCookies = new ClientRestTTCookies({
const denyCTTRestCookies = new CTTRestCookies({
access: {
canStore: false
},
Expand Down Expand Up @@ -52,12 +52,12 @@ describe('ClientRestTTBody', () => {
describe('setAccessToken', () => {

it('should set accessToken', () => {
defaultClientRestTTCookies.setAccessToken({}, {}, accessToken);
defaultCTTRestCookies.setAccessToken({}, {}, accessToken);
expect(mockcookie.str).toMatchSnapshot()
})

it('should not set accessToken if canStore is false', () => {
denyClientRestTTCookies.setAccessToken({}, {}, accessToken)
denyCTTRestCookies.setAccessToken({}, {}, accessToken)
expect(mockcookie.str).toBe('')
})

Expand All @@ -66,12 +66,12 @@ describe('ClientRestTTBody', () => {
describe('setRefreshToken', () => {

it('should set refreshToken', () => {
defaultClientRestTTCookies.setRefreshToken({}, {}, refreshToken)
defaultCTTRestCookies.setRefreshToken({}, {}, refreshToken)
expect(mockcookie.str).toMatchSnapshot()
})

it('should not set refreshToken if canStore is false', () => {
denyClientRestTTCookies.setRefreshToken({}, {}, refreshToken)
denyCTTRestCookies.setRefreshToken({}, {}, refreshToken)
expect(mockcookie.str).toBe('')
})

Expand All @@ -80,7 +80,7 @@ describe('ClientRestTTBody', () => {
describe('setTokens', () => {

it('should set both Tokens', () => {
defaultClientRestTTCookies.setTokens({},{},tokens)
defaultCTTRestCookies.setTokens({},{},tokens)
expect(mockcookie.str).toMatchSnapshot()
})

Expand All @@ -90,11 +90,11 @@ describe('ClientRestTTBody', () => {

it('should get accessToken', () => {
mockcookie.cookie = 'accessToken=' + accessToken;
expect(defaultClientRestTTCookies.getAccessToken()).toBe(accessToken);
expect(defaultCTTRestCookies.getAccessToken()).toBe(accessToken);
})

it('should return undefined if no accessToken', () => {
expect(defaultClientRestTTCookies.getAccessToken()).toBe(undefined)
expect(defaultCTTRestCookies.getAccessToken()).toBe(undefined)
})

})
Expand All @@ -103,11 +103,11 @@ describe('ClientRestTTBody', () => {

it('should get refreshToken', () => {
mockcookie.cookie = 'refreshToken=' + refreshToken;
expect(defaultClientRestTTCookies.getRefreshToken()).toBe(refreshToken)
expect(defaultCTTRestCookies.getRefreshToken()).toBe(refreshToken)
})

it('should return undefined if no refreshToken', () => {
expect(defaultClientRestTTCookies.getRefreshToken()).toBe(undefined)
expect(defaultCTTRestCookies.getRefreshToken()).toBe(undefined)
})

})
Expand All @@ -117,7 +117,7 @@ describe('ClientRestTTBody', () => {
it('should get both Tokens', () => {
document.cookie = 'accessToken=' + accessToken
document.cookie = 'refreshToken=' + refreshToken
expect(defaultClientRestTTCookies.getTokens()).toEqual(tokens)
expect(defaultCTTRestCookies.getTokens()).toEqual(tokens)
})

})
Expand Down
7 changes: 7 additions & 0 deletions packages/ctt-rest-cookies/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import CTTRestCookies from '../src';

describe('CTTRestCookies entry', () => {
it('should have default export CTTRestCookies', () => {
expect(typeof CTTRestCookies).toBe('function');
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@accounts/client-rest-tt-cookies",
"name": "@accounts/ctt-rest-cookies",
"version": "0.1.0-beta.10",
"description": "Accounts-JS Client Rest Transport Token Cookies",
"description": "Accounts-JS Client Token Transport Rest Cookies",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"publishConfig": {
Expand Down Expand Up @@ -29,7 +29,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/accounts-js/accounts/tree/master/packages/client-rest-tt-cookies"
"url": "https://github.com/accounts-js/accounts/tree/master/packages/ctt-rest-cookies"
},
"keywords": [
"accounts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const defaultConfig: Configuration<TokenConfiguration> = {
}
}

export default class ClientRestTTCookies {
export default class ClientTokenTransportRestCookies {

private accessConfig: TokenConfiguration;
private refreshConfig: TokenConfiguration;
Expand Down
1 change: 1 addition & 0 deletions packages/ctt-rest-cookies/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './ctt-rest-cookies';
Loading