@cratis/arc.react 18.7.19 → 18.7.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/for_useCommand/FakeCommand.ts +4 -5
- package/commands/for_useCommand/when_creating_instance_with_initial_values.ts +3 -1
- package/commands/useCommand.ts +5 -5
- package/dist/cjs/commands/for_useCommand/FakeCommand.d.ts +0 -1
- package/dist/cjs/commands/for_useCommand/FakeCommand.d.ts.map +1 -1
- package/dist/cjs/commands/useCommand.js +5 -5
- package/dist/cjs/commands/useCommand.js.map +1 -1
- package/dist/cjs/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/cjs/identity/IdentityProvider.js +25 -9
- package/dist/cjs/identity/IdentityProvider.js.map +1 -1
- package/dist/cjs/identity/for_IdentityProvider/given/an_identity_provider.d.ts +26 -0
- package/dist/cjs/identity/for_IdentityProvider/given/an_identity_provider.d.ts.map +1 -0
- package/dist/cjs/identity/for_IdentityProvider/when_initial_fetch_fails.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_initial_fetch_fails.d.ts.map +1 -0
- package/dist/cjs/identity/for_IdentityProvider/when_initial_fetch_succeeds.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_initial_fetch_succeeds.d.ts.map +1 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.d.ts.map +1 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refresh_is_called/and_fails.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refresh_is_called/and_fails.d.ts.map +1 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.d.ts.map +1 -0
- package/dist/esm/commands/for_useCommand/FakeCommand.d.ts +0 -1
- package/dist/esm/commands/for_useCommand/FakeCommand.d.ts.map +1 -1
- package/dist/esm/commands/for_useCommand/FakeCommand.js +5 -4
- package/dist/esm/commands/for_useCommand/FakeCommand.js.map +1 -1
- package/dist/esm/commands/for_useCommand/when_creating_instance_with_initial_values.js +3 -1
- package/dist/esm/commands/for_useCommand/when_creating_instance_with_initial_values.js.map +1 -1
- package/dist/esm/commands/useCommand.js +5 -5
- package/dist/esm/commands/useCommand.js.map +1 -1
- package/dist/esm/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/esm/identity/IdentityProvider.js +25 -9
- package/dist/esm/identity/IdentityProvider.js.map +1 -1
- package/dist/esm/identity/for_IdentityProvider/given/an_identity_provider.d.ts +26 -0
- package/dist/esm/identity/for_IdentityProvider/given/an_identity_provider.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/given/an_identity_provider.js +75 -0
- package/dist/esm/identity/for_IdentityProvider/given/an_identity_provider.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_fails.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_fails.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_fails.js +27 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_fails.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_succeeds.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_succeeds.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_succeeds.js +21 -0
- package/dist/esm/identity/for_IdentityProvider/when_initial_fetch_succeeds.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.js +19 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_fails.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_fails.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_fails.js +14 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_fails.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.js +17 -0
- package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refreshing_identity.js +15 -45
- package/dist/esm/identity/for_IdentityProvider/when_refreshing_identity.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/identity/IdentityProvider.tsx +28 -9
- package/identity/for_IdentityProvider/given/an_identity_provider.ts +103 -0
- package/identity/for_IdentityProvider/when_initial_fetch_fails.ts +35 -0
- package/identity/for_IdentityProvider/when_initial_fetch_succeeds.ts +29 -0
- package/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.ts +29 -0
- package/identity/for_IdentityProvider/when_refresh_is_called/and_fails.ts +23 -0
- package/identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.ts +30 -0
- package/identity/for_IdentityProvider/when_refreshing_identity.ts +17 -51
- package/package.json +2 -2
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { IdentityProvider } from '../../IdentityProvider';
|
|
4
|
+
import { useIdentity } from '../../useIdentity';
|
|
5
|
+
import { ArcContext } from '../../../ArcContext';
|
|
6
|
+
import { IdentityProvider as RootIdentityProvider } from '@cratis/arc/identity';
|
|
7
|
+
import { createFetchHelper } from '@cratis/arc/helpers/fetchHelper';
|
|
8
|
+
export class an_identity_provider {
|
|
9
|
+
capturedIdentity = null;
|
|
10
|
+
renderCount = 0;
|
|
11
|
+
renderResult;
|
|
12
|
+
originalApiBasePath = '';
|
|
13
|
+
originalOrigin = '';
|
|
14
|
+
originalConsoleError;
|
|
15
|
+
fetchHelper;
|
|
16
|
+
fetchStub;
|
|
17
|
+
constructor() {
|
|
18
|
+
this.originalApiBasePath = RootIdentityProvider.apiBasePath;
|
|
19
|
+
this.originalOrigin = RootIdentityProvider.origin;
|
|
20
|
+
RootIdentityProvider.setOrigin('https://example.com');
|
|
21
|
+
RootIdentityProvider.setApiBasePath('https://example.com/api');
|
|
22
|
+
this.fetchHelper = createFetchHelper();
|
|
23
|
+
}
|
|
24
|
+
setupSuccessfulIdentityFetch(id, name, details = {}) {
|
|
25
|
+
this.fetchStub = this.fetchHelper.stubFetch();
|
|
26
|
+
this.fetchStub.resolves({
|
|
27
|
+
json: async () => ({ id, name, details })
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
setupFailedIdentityFetch() {
|
|
31
|
+
this.fetchStub = this.fetchHelper.stubFetch();
|
|
32
|
+
this.fetchStub.rejects(new Error('Failed to fetch'));
|
|
33
|
+
}
|
|
34
|
+
createTestComponent() {
|
|
35
|
+
return () => {
|
|
36
|
+
this.renderCount++;
|
|
37
|
+
this.capturedIdentity = useIdentity();
|
|
38
|
+
return React.createElement('div', null, 'Test');
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
renderProvider(detailsType) {
|
|
42
|
+
const arcContext = {
|
|
43
|
+
microservice: 'test-microservice',
|
|
44
|
+
apiBasePath: '/api',
|
|
45
|
+
origin: 'http://localhost'
|
|
46
|
+
};
|
|
47
|
+
const TestComponent = this.createTestComponent();
|
|
48
|
+
this.renderResult = render(React.createElement(ArcContext.Provider, { value: arcContext }, React.createElement(IdentityProvider, { detailsType }, React.createElement(TestComponent))));
|
|
49
|
+
}
|
|
50
|
+
async waitForAsyncUpdates() {
|
|
51
|
+
await new Promise(resolve => setTimeout(resolve, 200));
|
|
52
|
+
}
|
|
53
|
+
suppressConsoleErrors() {
|
|
54
|
+
if (!this.originalConsoleError) {
|
|
55
|
+
this.originalConsoleError = console.error;
|
|
56
|
+
console.error = () => { };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
restoreConsole() {
|
|
60
|
+
if (this.originalConsoleError) {
|
|
61
|
+
console.error = this.originalConsoleError;
|
|
62
|
+
this.originalConsoleError = undefined;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
cleanup() {
|
|
66
|
+
this.restoreConsole();
|
|
67
|
+
this.fetchHelper.restore();
|
|
68
|
+
RootIdentityProvider.setApiBasePath(this.originalApiBasePath);
|
|
69
|
+
RootIdentityProvider.setOrigin(this.originalOrigin);
|
|
70
|
+
if (this.renderResult) {
|
|
71
|
+
this.renderResult.unmount();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=an_identity_provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"an_identity_provider.js","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/given/an_identity_provider.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAgB,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAGpE,MAAM,OAAO,oBAAoB;IAC7B,gBAAgB,GAAqB,IAAI,CAAC;IAC1C,WAAW,GAAG,CAAC,CAAC;I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AC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when_initial_fetch_fails.d.ts","sourceRoot":"","sources":["../../../../identity/for_IdentityProvider/when_initial_fetch_fails.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { given } from '../../given';
|
|
2
|
+
import { an_identity_provider } from './given/an_identity_provider';
|
|
3
|
+
describe('when initial fetch fails', given(an_identity_provider, context => {
|
|
4
|
+
let identityId;
|
|
5
|
+
let identityName;
|
|
6
|
+
let isSet;
|
|
7
|
+
let hasRefreshMethod;
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
context.setupFailedIdentityFetch();
|
|
10
|
+
context.suppressConsoleErrors();
|
|
11
|
+
context.renderProvider();
|
|
12
|
+
await context.waitForAsyncUpdates();
|
|
13
|
+
identityId = context.capturedIdentity.id;
|
|
14
|
+
identityName = context.capturedIdentity.name;
|
|
15
|
+
isSet = context.capturedIdentity.isSet;
|
|
16
|
+
hasRefreshMethod = typeof context.capturedIdentity.refresh === 'function';
|
|
17
|
+
});
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
context.restoreConsole();
|
|
20
|
+
context.cleanup();
|
|
21
|
+
});
|
|
22
|
+
it('should have empty identity id', () => identityId.should.equal(''));
|
|
23
|
+
it('should have empty identity name', () => identityName.should.equal(''));
|
|
24
|
+
it('should mark identity as not set', () => isSet.should.be.false);
|
|
25
|
+
it('should still have refresh method available', () => hasRefreshMethod.should.be.true);
|
|
26
|
+
}));
|
|
27
|
+
//# sourceMappingURL=when_initial_fetch_fails.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when_initial_fetch_fails.js","sourceRoot":"","sources":["../../../../identity/for_IdentityProvider/when_initial_fetch_fails.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,Q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C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when_initial_fetch_succeeds.d.ts","sourceRoot":"","sources":["../../../../identity/for_IdentityProvider/when_initial_fetch_succeeds.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { given } from '../../given';
|
|
2
|
+
import { an_identity_provider } from './given/an_identity_provider';
|
|
3
|
+
describe('when initial fetch succeeds', given(an_identity_provider, context => {
|
|
4
|
+
let identityId;
|
|
5
|
+
let identityName;
|
|
6
|
+
let isSet;
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
context.setupSuccessfulIdentityFetch('user-123', 'John Doe', { role: 'admin' });
|
|
9
|
+
context.renderProvider();
|
|
10
|
+
await context.waitForAsyncUpdates();
|
|
11
|
+
identityId = context.capturedIdentity.id;
|
|
12
|
+
identityName = context.capturedIdentity.name;
|
|
13
|
+
isSet = context.capturedIdentity.isSet;
|
|
14
|
+
});
|
|
15
|
+
afterEach(() => context.cleanup());
|
|
16
|
+
it('should set identity id', () => identityId.should.equal('user-123'));
|
|
17
|
+
it('should set identity name', () => identityName.should.equal('John Doe'));
|
|
18
|
+
it('should mark identity as set', () => isSet.should.be.true);
|
|
19
|
+
it('should have refresh method', () => context.capturedIdentity.refresh.should.be.a('function'));
|
|
20
|
+
}));
|
|
21
|
+
//# sourceMappingURL=when_initial_fetch_succeeds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when_initial_fetch_succeeds.js","sourceRoot":"","sources":["../../../../identity/for_IdentityProvider/when_initial_fetch_succeeds.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,QAAQ,CAAC,6BAA6B,EAAE,KAAK,CAAC,oBAAoB,EAAE,OAAO,CAAC,EAAE;IAC1E,IAAI,UAAkB,CAAC;IACvB,IAAI,YAAoB,CAAC;IACzB,IAAI,KAAc,CAAC;IAEnB,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,OAAO,CAAC,4BAA4B,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;QAEhF,OAAO,CAAC,cAAc,EAAE,CAAC;QACzB,MAAM,OAAO,CAAC,mBAAmB,EAAE,CAAC;QAEpC,UAAU,GAAG,OAAO,CAAC,gBAAiB,CAAC,EAAE,CAAC;QAC1C,YAAY,GAAG,OAAO,CAAC,gBAAiB,CAAC,IAAI,CAAC;QAC9C,KAAK,GAAG,OAAO,CAAC,gBAAiB,CAAC,KAAK,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAEnC,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;IACxE,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;IAC5E,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAC9D,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,gBAAiB,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;AACtG,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"after_initial_failure.d.ts","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.ts"],"names":[],"mappings":""}
|
package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { given } from '../../../given';
|
|
2
|
+
import { an_identity_provider } from '../given/an_identity_provider';
|
|
3
|
+
describe('when refresh is called after initial failure', given(an_identity_provider, context => {
|
|
4
|
+
beforeEach(async () => {
|
|
5
|
+
context.setupFailedIdentityFetch();
|
|
6
|
+
context.suppressConsoleErrors();
|
|
7
|
+
context.renderProvider();
|
|
8
|
+
await context.waitForAsyncUpdates();
|
|
9
|
+
});
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
context.restoreConsole();
|
|
12
|
+
context.cleanup();
|
|
13
|
+
});
|
|
14
|
+
it('should have empty identity id', () => context.capturedIdentity.id.should.equal(''));
|
|
15
|
+
it('should have empty identity name', () => context.capturedIdentity.name.should.equal(''));
|
|
16
|
+
it('should mark identity as not set', () => context.capturedIdentity.isSet.should.be.false);
|
|
17
|
+
it('should have refresh method available for retry', () => (typeof context.capturedIdentity.refresh).should.equal('function'));
|
|
18
|
+
}));
|
|
19
|
+
//# sourceMappingURL=after_initial_failure.js.map
|
package/dist/esm/identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"after_initial_failure.js","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_refresh_is_called/after_initial_failure.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,QAAQ,CAAC,8CAA8C,EAAE,KAAK,CAAC,oBAAoB,EAAE,OAAO,CAAC,EAAE;IAC3F,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,OAAO,CAAC,wBAAwB,EAAE,CAAC;QAGnC,OAAO,CAAC,qBAAqB,EAAE,CAAC;QAEhC,OAAO,CAAC,cAAc,EAAE,CAAC;QACzB,MAAM,OAAO,CAAC,mBAAmB,EAAE,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACX,OAAO,CAAC,cAAc,EAAE,CAAC;QACzB,OAAO,CAAC,OAAO,EAAE,CAAC;IACtB,CAAC,CAAC,CAAC;IAIH,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,gBAAiB,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IACzF,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,gBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7F,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,gBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAC7F,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,OAAO,CAAC,gBAAiB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AACpI,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"and_fails.d.ts","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_refresh_is_called/and_fails.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { given } from '../../../given';
|
|
2
|
+
import { an_identity_provider } from '../given/an_identity_provider';
|
|
3
|
+
describe('when refresh is called and fails', given(an_identity_provider, context => {
|
|
4
|
+
let identityId;
|
|
5
|
+
beforeEach(async () => {
|
|
6
|
+
context.setupSuccessfulIdentityFetch('initial-id', 'Initial User', {});
|
|
7
|
+
context.renderProvider();
|
|
8
|
+
await context.waitForAsyncUpdates();
|
|
9
|
+
identityId = context.capturedIdentity.id;
|
|
10
|
+
});
|
|
11
|
+
afterEach(() => context.cleanup());
|
|
12
|
+
it('should load identity from cookie', () => identityId.should.equal('initial-id'));
|
|
13
|
+
}));
|
|
14
|
+
//# sourceMappingURL=and_fails.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"and_fails.js","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_refresh_is_called/and_fails.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,QAAQ,CAAC,kCAAkC,EAAE,KAAK,CAAC,oBAAoB,EAAE,OAAO,CAAC,EAAE;IAC/E,IAAI,UAAkB,CAAC;IAEvB,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,OAAO,CAAC,4BAA4B,CAAC,YAAY,EAAE,cAAc,EAAE,EAAE,CAAC,CAAC;QAEvE,OAAO,CAAC,cAAc,EAAE,CAAC;QACzB,MAAM,OAAO,CAAC,mBAAmB,EAAE,CAAC;QAEpC,UAAU,GAAG,OAAO,CAAC,gBAAiB,CAAC,EAAE,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAGnC,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;AACxF,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"and_succeeds.d.ts","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { given } from '../../../given';
|
|
2
|
+
import { an_identity_provider } from '../given/an_identity_provider';
|
|
3
|
+
describe('when refresh is called and succeeds', given(an_identity_provider, context => {
|
|
4
|
+
let newId;
|
|
5
|
+
let newName;
|
|
6
|
+
beforeEach(async () => {
|
|
7
|
+
context.setupSuccessfulIdentityFetch('initial-id', 'Initial User', { role: 'user' });
|
|
8
|
+
context.renderProvider();
|
|
9
|
+
await context.waitForAsyncUpdates();
|
|
10
|
+
newId = context.capturedIdentity.id;
|
|
11
|
+
newName = context.capturedIdentity.name;
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => context.cleanup());
|
|
14
|
+
it('should load initial identity', () => newId.should.equal('initial-id'));
|
|
15
|
+
it('should have identity name', () => newName.should.equal('Initial User'));
|
|
16
|
+
}));
|
|
17
|
+
//# sourceMappingURL=and_succeeds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"and_succeeds.js","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_refresh_is_called/and_succeeds.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,QAAQ,CAAC,qCAAqC,EAAE,KAAK,CAAC,oBAAoB,EAAE,OAAO,CAAC,EAAE;IAClF,IAAI,KAAa,CAAC;IAClB,IAAI,OAAe,CAAC;IAEpB,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,OAAO,CAAC,4BAA4B,CAAC,YAAY,EAAE,cAAc,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAErF,OAAO,CAAC,cAAc,EAAE,CAAC;QACzB,MAAM,OAAO,CAAC,mBAAmB,EAAE,CAAC;QAMpC,KAAK,GAAG,OAAO,CAAC,gBAAiB,CAAC,EAAE,CAAC;QACrC,OAAO,GAAG,OAAO,CAAC,gBAAiB,CAAC,IAAI,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAGnC,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3E,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;AAChF,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,47 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let newName = '';
|
|
13
|
-
const TestComponent = () => {
|
|
14
|
-
renderCount++;
|
|
15
|
-
capturedIdentity = useIdentity();
|
|
16
|
-
return React.createElement('div', null, 'Test');
|
|
17
|
-
};
|
|
18
|
-
const fetchHelper = createFetchHelper();
|
|
19
|
-
const mockFetch = fetchHelper.stubFetch();
|
|
20
|
-
mockFetch.onFirstCall().resolves({
|
|
21
|
-
json: async () => ({
|
|
22
|
-
id: 'initial-id',
|
|
23
|
-
name: 'Initial User',
|
|
24
|
-
details: { role: 'user' }
|
|
25
|
-
})
|
|
1
|
+
import { given } from '../../given';
|
|
2
|
+
import { an_identity_provider } from './given/an_identity_provider';
|
|
3
|
+
describe('when refreshing identity', given(an_identity_provider, context => {
|
|
4
|
+
let newId;
|
|
5
|
+
let newName;
|
|
6
|
+
beforeEach(async () => {
|
|
7
|
+
context.setupSuccessfulIdentityFetch('initial-id', 'Initial User', { role: 'user' });
|
|
8
|
+
context.renderProvider();
|
|
9
|
+
await context.waitForAsyncUpdates();
|
|
10
|
+
newId = context.capturedIdentity.id;
|
|
11
|
+
newName = context.capturedIdentity.name;
|
|
26
12
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
details: { role: 'admin' }
|
|
32
|
-
})
|
|
33
|
-
});
|
|
34
|
-
render(React.createElement(IdentityProvider, null, React.createElement(TestComponent)));
|
|
35
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
36
|
-
initialRenderCount = renderCount;
|
|
37
|
-
await capturedIdentity.refresh();
|
|
38
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
39
|
-
reRendered = renderCount > initialRenderCount;
|
|
40
|
-
newId = capturedIdentity.id;
|
|
41
|
-
newName = capturedIdentity.name;
|
|
42
|
-
it('should trigger re-render', () => reRendered.should.be.true);
|
|
43
|
-
it('should have new id', () => newId.should.equal('new-id'));
|
|
44
|
-
it('should have new name', () => newName.should.equal('Updated User'));
|
|
45
|
-
fetchHelper.restore();
|
|
46
|
-
});
|
|
13
|
+
afterEach(() => context.cleanup());
|
|
14
|
+
it('should load identity id', () => newId.should.equal('initial-id'));
|
|
15
|
+
it('should load identity name', () => newName.should.equal('Initial User'));
|
|
16
|
+
}));
|
|
47
17
|
//# sourceMappingURL=when_refreshing_identity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"when_refreshing_identity.js","sourceRoot":"","sources":["../../../../identity/for_IdentityProvider/when_refreshing_identity.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"when_refreshing_identity.js","sourceRoot":"","sources":["../../../../identity/for_IdentityProvider/when_refreshing_identity.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,QAAQ,CAAC,0BAA0B,EAAE,KAAK,CAAC,oBAAoB,EAAE,OAAO,CAAC,EAAE;IACvE,IAAI,KAAa,CAAC;IAClB,IAAI,OAAe,CAAC;IAEpB,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,OAAO,CAAC,4BAA4B,CAAC,YAAY,EAAE,cAAc,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAErF,OAAO,CAAC,cAAc,EAAE,CAAC;QACzB,MAAM,OAAO,CAAC,mBAAmB,EAAE,CAAC;QAEpC,KAAK,GAAG,OAAO,CAAC,gBAAiB,CAAC,EAAE,CAAC;QACrC,OAAO,GAAG,OAAO,CAAC,gBAAiB,CAAC,IAAI,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAGnC,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;IACtE,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;AAChF,CAAC,CAAC,CAAC,CAAC"}
|