@sprucelabs/spruce-test-fixtures 52.3.22 → 52.3.23
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/build/__tests__/behavioral/views/CheckingPermissions.test.d.ts +1 -0
- package/build/__tests__/behavioral/views/CheckingPermissions.test.js +18 -3
- package/build/__tests__/behavioral/views/Routing.test.js +2 -2
- package/build/esm/__tests__/behavioral/views/CheckingPermissions.test.d.ts +1 -0
- package/build/esm/__tests__/behavioral/views/CheckingPermissions.test.js +20 -3
- package/build/esm/__tests__/behavioral/views/Routing.test.js +2 -2
- package/build/esm/tests/{SpyAuthorizer.d.ts → FakeAuthorizer.d.ts} +4 -2
- package/build/esm/tests/{SpyAuthorizer.js → FakeAuthorizer.js} +18 -11
- package/build/esm/tests/fixtures/ViewFixture.d.ts +2 -2
- package/build/esm/tests/fixtures/ViewFixture.js +3 -3
- package/build/esm/tests/routers/TestRouter.js +2 -2
- package/build/tests/{SpyAuthorizer.d.ts → FakeAuthorizer.d.ts} +4 -2
- package/build/tests/{SpyAuthorizer.js → FakeAuthorizer.js} +19 -12
- package/build/tests/fixtures/ViewFixture.d.ts +2 -2
- package/build/tests/fixtures/ViewFixture.js +3 -3
- package/build/tests/routers/TestRouter.js +2 -2
- package/package.json +3 -3
|
@@ -14,6 +14,7 @@ export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
|
|
|
14
14
|
protected static returnsFakedResponses(permissionIds: string[], can: boolean): Promise<void>;
|
|
15
15
|
protected static fixtureAndLoadOptionsShareAuthorizer(): Promise<void>;
|
|
16
16
|
protected static authorizerClobbersMatchingContracts(): Promise<void>;
|
|
17
|
+
protected static usesLatestMatchWhenMultipleSent(): Promise<void>;
|
|
17
18
|
protected static canHandleMulplePermissionsWithDifferentContracts(): Promise<void>;
|
|
18
19
|
private static assertPermNotFound;
|
|
19
20
|
private static changeContractId;
|
|
@@ -12,15 +12,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
13
13
|
const test_utils_2 = require("@sprucelabs/test-utils");
|
|
14
14
|
const AbstractSpruceFixtureTest_1 = __importDefault(require("../../../tests/AbstractSpruceFixtureTest"));
|
|
15
|
+
const FakeAuthorizer_1 = __importDefault(require("../../../tests/FakeAuthorizer"));
|
|
15
16
|
const ViewFixture_1 = __importDefault(require("../../../tests/fixtures/ViewFixture"));
|
|
16
|
-
const SpyAuthorizer_1 = __importDefault(require("../../../tests/SpyAuthorizer"));
|
|
17
17
|
class CheckingPermissionsTest extends AbstractSpruceFixtureTest_1.default {
|
|
18
18
|
static async beforeEach() {
|
|
19
19
|
await super.beforeEach();
|
|
20
20
|
this.contractId = (0, test_utils_2.generateId)();
|
|
21
21
|
}
|
|
22
22
|
static async canCreateCheckingPermissions() {
|
|
23
|
-
test_utils_1.assert.isTrue(this.instance instanceof
|
|
23
|
+
test_utils_1.assert.isTrue(this.instance instanceof FakeAuthorizer_1.default);
|
|
24
24
|
}
|
|
25
25
|
static async sharesInstances() {
|
|
26
26
|
test_utils_1.assert.isEqual(this.instance, this.instance);
|
|
@@ -82,6 +82,18 @@ class CheckingPermissionsTest extends AbstractSpruceFixtureTest_1.default {
|
|
|
82
82
|
const perms = await this.can(['test']);
|
|
83
83
|
test_utils_1.assert.isFalse(perms['test']);
|
|
84
84
|
}
|
|
85
|
+
static async usesLatestMatchWhenMultipleSent() {
|
|
86
|
+
this.fakePermissions([
|
|
87
|
+
{ id: 'test', can: false },
|
|
88
|
+
{ id: 'test2', can: false },
|
|
89
|
+
]);
|
|
90
|
+
this.fakePermissions([
|
|
91
|
+
{ id: 'test', can: true },
|
|
92
|
+
{ id: 'test2', can: false },
|
|
93
|
+
]);
|
|
94
|
+
const perms = await this.can(['test', 'test2']);
|
|
95
|
+
test_utils_1.assert.isTrue(perms['test']);
|
|
96
|
+
}
|
|
85
97
|
static async canHandleMulplePermissionsWithDifferentContracts() {
|
|
86
98
|
const firstId = this.contractId;
|
|
87
99
|
this.fakePermissions([{ id: 'test', can: true }]);
|
|
@@ -113,7 +125,7 @@ class CheckingPermissionsTest extends AbstractSpruceFixtureTest_1.default {
|
|
|
113
125
|
});
|
|
114
126
|
}
|
|
115
127
|
static get instance() {
|
|
116
|
-
return
|
|
128
|
+
return FakeAuthorizer_1.default.getInstance();
|
|
117
129
|
}
|
|
118
130
|
}
|
|
119
131
|
__decorate([
|
|
@@ -155,6 +167,9 @@ __decorate([
|
|
|
155
167
|
__decorate([
|
|
156
168
|
(0, test_utils_1.test)()
|
|
157
169
|
], CheckingPermissionsTest, "authorizerClobbersMatchingContracts", null);
|
|
170
|
+
__decorate([
|
|
171
|
+
(0, test_utils_1.test)()
|
|
172
|
+
], CheckingPermissionsTest, "usesLatestMatchWhenMultipleSent", null);
|
|
158
173
|
__decorate([
|
|
159
174
|
(0, test_utils_1.test)()
|
|
160
175
|
], CheckingPermissionsTest, "canHandleMulplePermissionsWithDifferentContracts", null);
|
|
@@ -17,8 +17,8 @@ const test_utils_1 = require("@sprucelabs/test-utils");
|
|
|
17
17
|
const test_utils_2 = require("@sprucelabs/test-utils");
|
|
18
18
|
const AbstractSpruceFixtureTest_1 = __importDefault(require("../../../tests/AbstractSpruceFixtureTest"));
|
|
19
19
|
const Fake_svc_1 = __importDefault(require("../../../tests/Fake.svc"));
|
|
20
|
+
const FakeAuthorizer_1 = __importDefault(require("../../../tests/FakeAuthorizer"));
|
|
20
21
|
const TestRouter_1 = __importDefault(require("../../../tests/routers/TestRouter"));
|
|
21
|
-
const SpyAuthorizer_1 = __importDefault(require("../../../tests/SpyAuthorizer"));
|
|
22
22
|
const Book_svc_1 = __importDefault(require("../../testDirsAndFiles/skill/build/skillViewControllers/Book.svc"));
|
|
23
23
|
const Spy_svc_1 = __importDefault(require("../../testDirsAndFiles/skill/build/skillViewControllers/Spy.svc"));
|
|
24
24
|
class RoutingTest extends AbstractSpruceFixtureTest_1.default {
|
|
@@ -94,7 +94,7 @@ class RoutingTest extends AbstractSpruceFixtureTest_1.default {
|
|
|
94
94
|
static testRouterBuildsOptionsWithLocaleAndAuthorizer() {
|
|
95
95
|
const options = this.router.buildLoadOptions();
|
|
96
96
|
test_utils_1.assert.isTrue(options.locale instanceof calendar_utils_1.LocaleImpl);
|
|
97
|
-
test_utils_1.assert.isTrue(options.authorizer instanceof
|
|
97
|
+
test_utils_1.assert.isTrue(options.authorizer instanceof FakeAuthorizer_1.default);
|
|
98
98
|
}
|
|
99
99
|
static async assertRedirects(action) {
|
|
100
100
|
return heartwood_view_controllers_1.vcAssert.assertActionRedirects({
|
|
@@ -14,6 +14,7 @@ export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
|
|
|
14
14
|
protected static returnsFakedResponses(permissionIds: string[], can: boolean): Promise<void>;
|
|
15
15
|
protected static fixtureAndLoadOptionsShareAuthorizer(): Promise<void>;
|
|
16
16
|
protected static authorizerClobbersMatchingContracts(): Promise<void>;
|
|
17
|
+
protected static usesLatestMatchWhenMultipleSent(): Promise<void>;
|
|
17
18
|
protected static canHandleMulplePermissionsWithDifferentContracts(): Promise<void>;
|
|
18
19
|
private static assertPermNotFound;
|
|
19
20
|
private static changeContractId;
|
|
@@ -16,8 +16,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
16
16
|
import { test, assert } from '@sprucelabs/test-utils';
|
|
17
17
|
import { errorAssert, generateId } from '@sprucelabs/test-utils';
|
|
18
18
|
import AbstractSpruceFixtureTest from '../../../tests/AbstractSpruceFixtureTest.js';
|
|
19
|
+
import FakeAuthorizer from '../../../tests/FakeAuthorizer.js';
|
|
19
20
|
import ViewFixture from '../../../tests/fixtures/ViewFixture.js';
|
|
20
|
-
import SpyAuthorizer from '../../../tests/SpyAuthorizer.js';
|
|
21
21
|
export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
|
|
22
22
|
static beforeEach() {
|
|
23
23
|
const _super = Object.create(null, {
|
|
@@ -30,7 +30,7 @@ export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
|
|
|
30
30
|
}
|
|
31
31
|
static canCreateCheckingPermissions() {
|
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
assert.isTrue(this.instance instanceof
|
|
33
|
+
assert.isTrue(this.instance instanceof FakeAuthorizer);
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
static sharesInstances() {
|
|
@@ -115,6 +115,20 @@ export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
|
|
|
115
115
|
assert.isFalse(perms['test']);
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
|
+
static usesLatestMatchWhenMultipleSent() {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
this.fakePermissions([
|
|
121
|
+
{ id: 'test', can: false },
|
|
122
|
+
{ id: 'test2', can: false },
|
|
123
|
+
]);
|
|
124
|
+
this.fakePermissions([
|
|
125
|
+
{ id: 'test', can: true },
|
|
126
|
+
{ id: 'test2', can: false },
|
|
127
|
+
]);
|
|
128
|
+
const perms = yield this.can(['test', 'test2']);
|
|
129
|
+
assert.isTrue(perms['test']);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
118
132
|
static canHandleMulplePermissionsWithDifferentContracts() {
|
|
119
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
120
134
|
const firstId = this.contractId;
|
|
@@ -152,7 +166,7 @@ export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
|
|
|
152
166
|
});
|
|
153
167
|
}
|
|
154
168
|
static get instance() {
|
|
155
|
-
return
|
|
169
|
+
return FakeAuthorizer.getInstance();
|
|
156
170
|
}
|
|
157
171
|
}
|
|
158
172
|
__decorate([
|
|
@@ -194,6 +208,9 @@ __decorate([
|
|
|
194
208
|
__decorate([
|
|
195
209
|
test()
|
|
196
210
|
], CheckingPermissionsTest, "authorizerClobbersMatchingContracts", null);
|
|
211
|
+
__decorate([
|
|
212
|
+
test()
|
|
213
|
+
], CheckingPermissionsTest, "usesLatestMatchWhenMultipleSent", null);
|
|
197
214
|
__decorate([
|
|
198
215
|
test()
|
|
199
216
|
], CheckingPermissionsTest, "canHandleMulplePermissionsWithDifferentContracts", null);
|
|
@@ -21,8 +21,8 @@ import { test, assert } from '@sprucelabs/test-utils';
|
|
|
21
21
|
import { errorAssert } from '@sprucelabs/test-utils';
|
|
22
22
|
import AbstractSpruceFixtureTest from '../../../tests/AbstractSpruceFixtureTest.js';
|
|
23
23
|
import FakeSkillViewController from '../../../tests/Fake.svc.js';
|
|
24
|
+
import FakeAuthorizer from '../../../tests/FakeAuthorizer.js';
|
|
24
25
|
import TestRouter from '../../../tests/routers/TestRouter.js';
|
|
25
|
-
import SpyAuthorizer from '../../../tests/SpyAuthorizer.js';
|
|
26
26
|
import BookSkillViewController from '../../testDirsAndFiles/skill/build/skillViewControllers/Book.svc.js';
|
|
27
27
|
import SpySkillViewController from '../../testDirsAndFiles/skill/build/skillViewControllers/Spy.svc.js';
|
|
28
28
|
export default class RoutingTest extends AbstractSpruceFixtureTest {
|
|
@@ -121,7 +121,7 @@ export default class RoutingTest extends AbstractSpruceFixtureTest {
|
|
|
121
121
|
static testRouterBuildsOptionsWithLocaleAndAuthorizer() {
|
|
122
122
|
const options = this.router.buildLoadOptions();
|
|
123
123
|
assert.isTrue(options.locale instanceof LocaleImpl);
|
|
124
|
-
assert.isTrue(options.authorizer instanceof
|
|
124
|
+
assert.isTrue(options.authorizer instanceof FakeAuthorizer);
|
|
125
125
|
}
|
|
126
126
|
static assertRedirects(action) {
|
|
127
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Authorizer, AuthorizerCanOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { PermissionContractId, PermissionId } from '@sprucelabs/mercury-types';
|
|
3
|
-
export default class
|
|
3
|
+
export default class FakeAuthorizer implements Authorizer {
|
|
4
4
|
private static instance?;
|
|
5
5
|
private fakedPermissions;
|
|
6
|
-
static getInstance():
|
|
6
|
+
static getInstance(): FakeAuthorizer;
|
|
7
7
|
static reset(): void;
|
|
8
8
|
fakePermissions<ContractId extends PermissionContractId = PermissionContractId>(options: FakeOptions<ContractId>): void;
|
|
9
9
|
can<ContractId extends PermissionContractId, Ids extends PermissionId<ContractId>>(options: AuthorizerCanOptions<ContractId, Ids>): Promise<Record<Ids, boolean>>;
|
|
10
|
+
private assertValidPermission;
|
|
11
|
+
private assertValidContractId;
|
|
10
12
|
}
|
|
11
13
|
interface Perm<ContractId extends PermissionContractId> {
|
|
12
14
|
id: PermissionId<ContractId>;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { assertOptions } from '@sprucelabs/schema';
|
|
11
11
|
import { assert } from '@sprucelabs/test-utils';
|
|
12
|
-
export default class
|
|
12
|
+
export default class FakeAuthorizer {
|
|
13
13
|
constructor() {
|
|
14
14
|
this.fakedPermissions = [];
|
|
15
15
|
}
|
|
@@ -29,23 +29,30 @@ export default class SpyAuthorizer {
|
|
|
29
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
30
|
const { contractId, permissionIds } = assertOptions(options, ['contractId', 'permissionIds']);
|
|
31
31
|
const faked = this.fakedPermissions.find((f) => f.contractId === contractId);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Valid contracts are:
|
|
35
|
-
|
|
36
|
-
${this.fakedPermissions.map((p) => p.contractId).join('\n')}`);
|
|
32
|
+
this.assertValidContractId(faked, contractId);
|
|
37
33
|
const results = {};
|
|
34
|
+
permissionIds.reverse();
|
|
38
35
|
for (const actual of permissionIds) {
|
|
39
36
|
const fakedPerm = faked.permissions.find((p) => p.id === actual);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
Valid permissions on this contract are:
|
|
43
|
-
|
|
44
|
-
${faked.permissions.map((p) => p.id).join('\n')}`);
|
|
37
|
+
this.assertValidPermission(fakedPerm, actual, faked);
|
|
45
38
|
//@ts-ignore
|
|
46
39
|
permissionIds.forEach((id) => (results[id] = fakedPerm.can));
|
|
47
40
|
}
|
|
48
41
|
return results;
|
|
49
42
|
});
|
|
50
43
|
}
|
|
44
|
+
assertValidPermission(fakedPerm, actual, faked) {
|
|
45
|
+
assert.isTruthy(fakedPerm, `Oops! I could not find the permissionId '${actual}'! Make sure you faked it with 'this.views.getAuthorizer().fakePermissions(...)'
|
|
46
|
+
|
|
47
|
+
Valid permissions on this contract are:
|
|
48
|
+
|
|
49
|
+
${faked.permissions.map((p) => p.id).join('\n')}`);
|
|
50
|
+
}
|
|
51
|
+
assertValidContractId(faked, contractId) {
|
|
52
|
+
assert.isTruthy(faked, `Contract by the id '${contractId}' not found! You need to tell the authorizer how to respond. Try 'this.views.getAuthorizer().fakePermissions(...)'
|
|
53
|
+
|
|
54
|
+
Valid contracts are:
|
|
55
|
+
|
|
56
|
+
${this.fakedPermissions.map((p) => p.contractId).join('\n')}`);
|
|
57
|
+
}
|
|
51
58
|
}
|
|
@@ -6,8 +6,8 @@ import { ClientProxyDecorator } from '../..';
|
|
|
6
6
|
import { TokenGenerator } from '../../ClientProxyDecorator';
|
|
7
7
|
import { TestConnectFactory } from '../../types/fixture.types';
|
|
8
8
|
import { ArgsFromSvc } from '../../types/view.types';
|
|
9
|
+
import FakeAuthorizer from '../FakeAuthorizer';
|
|
9
10
|
import TestRouter from '../routers/TestRouter';
|
|
10
|
-
import SpyAuthorizer from '../SpyAuthorizer';
|
|
11
11
|
import FixtureFactory from './FixtureFactory';
|
|
12
12
|
import PersonFixture from './PersonFixture';
|
|
13
13
|
import SpyScope from './SpyScope';
|
|
@@ -60,7 +60,7 @@ export default class ViewFixture {
|
|
|
60
60
|
getLocale(): Locale;
|
|
61
61
|
getRouter(): TestRouter;
|
|
62
62
|
getAuthenticator(): import("@sprucelabs/heartwood-view-controllers").Authenticator;
|
|
63
|
-
getAuthorizer():
|
|
63
|
+
getAuthorizer(): FakeAuthorizer;
|
|
64
64
|
getProxyTokenGenerator(): TokenGenerator | undefined;
|
|
65
65
|
setProxyTokenGenerator(cb: TokenGenerator): void;
|
|
66
66
|
loginAsDemoPerson(phone?: string): Promise<{
|
|
@@ -16,8 +16,8 @@ import SpruceError from '../../errors/SpruceError.js';
|
|
|
16
16
|
import spyMapUtil from '../../utilities/SpyMapUtil.js';
|
|
17
17
|
import vcDiskUtil from '../../utilities/vcDisk.utility.js';
|
|
18
18
|
import FakeSkillViewController from '../Fake.svc.js';
|
|
19
|
+
import FakeAuthorizer from '../FakeAuthorizer.js';
|
|
19
20
|
import TestRouter from '../routers/TestRouter.js';
|
|
20
|
-
import SpyAuthorizer from '../SpyAuthorizer.js';
|
|
21
21
|
import SpyScope from './SpyScope.js';
|
|
22
22
|
export default class ViewFixture {
|
|
23
23
|
static lockProxyCacheForPerson(id) {
|
|
@@ -154,7 +154,7 @@ export default class ViewFixture {
|
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
TestRouter.reset();
|
|
157
|
-
|
|
157
|
+
FakeAuthorizer.reset();
|
|
158
158
|
ViewFixture.resetMaps();
|
|
159
159
|
ActiveRecordCardViewController.setShouldThrowOnResponseError(true);
|
|
160
160
|
process.env.SHOULD_REGISTER_VIEWS = 'false';
|
|
@@ -229,7 +229,7 @@ export default class ViewFixture {
|
|
|
229
229
|
return AuthenticatorImpl.getInstance();
|
|
230
230
|
}
|
|
231
231
|
getAuthorizer() {
|
|
232
|
-
return
|
|
232
|
+
return FakeAuthorizer.getInstance();
|
|
233
233
|
}
|
|
234
234
|
getProxyTokenGenerator() {
|
|
235
235
|
return this.proxyDecorator.getProxyTokenGenerator();
|
|
@@ -12,7 +12,7 @@ import { AbstractEventEmitter } from '@sprucelabs/mercury-event-emitter';
|
|
|
12
12
|
import { buildEventContract, } from '@sprucelabs/mercury-types';
|
|
13
13
|
import testRouterEmitPayloadSchema from './../../.spruce/schemas/spruceTestFixtures/v2021_07_19/testRouterEmitPayload.schema.js';
|
|
14
14
|
import FakeThemeManager from '../../__tests__/support/FakeThemeManager.js';
|
|
15
|
-
import
|
|
15
|
+
import FakeAuthorizer from '../FakeAuthorizer.js';
|
|
16
16
|
const contract = buildEventContract({
|
|
17
17
|
eventSignatures: {
|
|
18
18
|
'did-redirect': {
|
|
@@ -93,7 +93,7 @@ export default class TestRouter extends AbstractEventEmitter {
|
|
|
93
93
|
authenticator: AuthenticatorImpl.getInstance(),
|
|
94
94
|
args,
|
|
95
95
|
locale: this.locale,
|
|
96
|
-
authorizer:
|
|
96
|
+
authorizer: FakeAuthorizer.getInstance(),
|
|
97
97
|
scope: this.scope,
|
|
98
98
|
themes: this.themes,
|
|
99
99
|
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Authorizer, AuthorizerCanOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { PermissionContractId, PermissionId } from '@sprucelabs/mercury-types';
|
|
3
|
-
export default class
|
|
3
|
+
export default class FakeAuthorizer implements Authorizer {
|
|
4
4
|
private static instance?;
|
|
5
5
|
private fakedPermissions;
|
|
6
|
-
static getInstance():
|
|
6
|
+
static getInstance(): FakeAuthorizer;
|
|
7
7
|
static reset(): void;
|
|
8
8
|
fakePermissions<ContractId extends PermissionContractId = PermissionContractId>(options: FakeOptions<ContractId>): void;
|
|
9
9
|
can<ContractId extends PermissionContractId, Ids extends PermissionId<ContractId>>(options: AuthorizerCanOptions<ContractId, Ids>): Promise<Record<Ids, boolean>>;
|
|
10
|
+
private assertValidPermission;
|
|
11
|
+
private assertValidContractId;
|
|
10
12
|
}
|
|
11
13
|
interface Perm<ContractId extends PermissionContractId> {
|
|
12
14
|
id: PermissionId<ContractId>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const schema_1 = require("@sprucelabs/schema");
|
|
4
4
|
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
5
|
-
class
|
|
5
|
+
class FakeAuthorizer {
|
|
6
6
|
constructor() {
|
|
7
7
|
this.fakedPermissions = [];
|
|
8
8
|
}
|
|
@@ -21,23 +21,30 @@ class SpyAuthorizer {
|
|
|
21
21
|
async can(options) {
|
|
22
22
|
const { contractId, permissionIds } = (0, schema_1.assertOptions)(options, ['contractId', 'permissionIds']);
|
|
23
23
|
const faked = this.fakedPermissions.find((f) => f.contractId === contractId);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
Valid contracts are:
|
|
27
|
-
|
|
28
|
-
${this.fakedPermissions.map((p) => p.contractId).join('\n')}`);
|
|
24
|
+
this.assertValidContractId(faked, contractId);
|
|
29
25
|
const results = {};
|
|
26
|
+
permissionIds.reverse();
|
|
30
27
|
for (const actual of permissionIds) {
|
|
31
28
|
const fakedPerm = faked.permissions.find((p) => p.id === actual);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Valid permissions on this contract are:
|
|
35
|
-
|
|
36
|
-
${faked.permissions.map((p) => p.id).join('\n')}`);
|
|
29
|
+
this.assertValidPermission(fakedPerm, actual, faked);
|
|
37
30
|
//@ts-ignore
|
|
38
31
|
permissionIds.forEach((id) => (results[id] = fakedPerm.can));
|
|
39
32
|
}
|
|
40
33
|
return results;
|
|
41
34
|
}
|
|
35
|
+
assertValidPermission(fakedPerm, actual, faked) {
|
|
36
|
+
test_utils_1.assert.isTruthy(fakedPerm, `Oops! I could not find the permissionId '${actual}'! Make sure you faked it with 'this.views.getAuthorizer().fakePermissions(...)'
|
|
37
|
+
|
|
38
|
+
Valid permissions on this contract are:
|
|
39
|
+
|
|
40
|
+
${faked.permissions.map((p) => p.id).join('\n')}`);
|
|
41
|
+
}
|
|
42
|
+
assertValidContractId(faked, contractId) {
|
|
43
|
+
test_utils_1.assert.isTruthy(faked, `Contract by the id '${contractId}' not found! You need to tell the authorizer how to respond. Try 'this.views.getAuthorizer().fakePermissions(...)'
|
|
44
|
+
|
|
45
|
+
Valid contracts are:
|
|
46
|
+
|
|
47
|
+
${this.fakedPermissions.map((p) => p.contractId).join('\n')}`);
|
|
48
|
+
}
|
|
42
49
|
}
|
|
43
|
-
exports.default =
|
|
50
|
+
exports.default = FakeAuthorizer;
|
|
@@ -6,8 +6,8 @@ import { ClientProxyDecorator } from '../..';
|
|
|
6
6
|
import { TokenGenerator } from '../../ClientProxyDecorator';
|
|
7
7
|
import { TestConnectFactory } from '../../types/fixture.types';
|
|
8
8
|
import { ArgsFromSvc } from '../../types/view.types';
|
|
9
|
+
import FakeAuthorizer from '../FakeAuthorizer';
|
|
9
10
|
import TestRouter from '../routers/TestRouter';
|
|
10
|
-
import SpyAuthorizer from '../SpyAuthorizer';
|
|
11
11
|
import FixtureFactory from './FixtureFactory';
|
|
12
12
|
import PersonFixture from './PersonFixture';
|
|
13
13
|
import SpyScope from './SpyScope';
|
|
@@ -60,7 +60,7 @@ export default class ViewFixture {
|
|
|
60
60
|
getLocale(): Locale;
|
|
61
61
|
getRouter(): TestRouter;
|
|
62
62
|
getAuthenticator(): import("@sprucelabs/heartwood-view-controllers").Authenticator;
|
|
63
|
-
getAuthorizer():
|
|
63
|
+
getAuthorizer(): FakeAuthorizer;
|
|
64
64
|
getProxyTokenGenerator(): TokenGenerator | undefined;
|
|
65
65
|
setProxyTokenGenerator(cb: TokenGenerator): void;
|
|
66
66
|
loginAsDemoPerson(phone?: string): Promise<{
|
|
@@ -12,8 +12,8 @@ const SpruceError_1 = __importDefault(require("../../errors/SpruceError"));
|
|
|
12
12
|
const SpyMapUtil_1 = __importDefault(require("../../utilities/SpyMapUtil"));
|
|
13
13
|
const vcDisk_utility_1 = __importDefault(require("../../utilities/vcDisk.utility"));
|
|
14
14
|
const Fake_svc_1 = __importDefault(require("../Fake.svc"));
|
|
15
|
+
const FakeAuthorizer_1 = __importDefault(require("../FakeAuthorizer"));
|
|
15
16
|
const TestRouter_1 = __importDefault(require("../routers/TestRouter"));
|
|
16
|
-
const SpyAuthorizer_1 = __importDefault(require("../SpyAuthorizer"));
|
|
17
17
|
const SpyScope_1 = __importDefault(require("./SpyScope"));
|
|
18
18
|
class ViewFixture {
|
|
19
19
|
static lockProxyCacheForPerson(id) {
|
|
@@ -147,7 +147,7 @@ class ViewFixture {
|
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
149
|
TestRouter_1.default.reset();
|
|
150
|
-
|
|
150
|
+
FakeAuthorizer_1.default.reset();
|
|
151
151
|
ViewFixture.resetMaps();
|
|
152
152
|
heartwood_view_controllers_1.ActiveRecordCardViewController.setShouldThrowOnResponseError(true);
|
|
153
153
|
process.env.SHOULD_REGISTER_VIEWS = 'false';
|
|
@@ -217,7 +217,7 @@ class ViewFixture {
|
|
|
217
217
|
return heartwood_view_controllers_1.AuthenticatorImpl.getInstance();
|
|
218
218
|
}
|
|
219
219
|
getAuthorizer() {
|
|
220
|
-
return
|
|
220
|
+
return FakeAuthorizer_1.default.getInstance();
|
|
221
221
|
}
|
|
222
222
|
getProxyTokenGenerator() {
|
|
223
223
|
return this.proxyDecorator.getProxyTokenGenerator();
|
|
@@ -8,7 +8,7 @@ const mercury_event_emitter_1 = require("@sprucelabs/mercury-event-emitter");
|
|
|
8
8
|
const mercury_types_1 = require("@sprucelabs/mercury-types");
|
|
9
9
|
const testRouterEmitPayload_schema_1 = __importDefault(require("./../../.spruce/schemas/spruceTestFixtures/v2021_07_19/testRouterEmitPayload.schema"));
|
|
10
10
|
const FakeThemeManager_1 = __importDefault(require("../../__tests__/support/FakeThemeManager"));
|
|
11
|
-
const
|
|
11
|
+
const FakeAuthorizer_1 = __importDefault(require("../FakeAuthorizer"));
|
|
12
12
|
const contract = (0, mercury_types_1.buildEventContract)({
|
|
13
13
|
eventSignatures: {
|
|
14
14
|
'did-redirect': {
|
|
@@ -85,7 +85,7 @@ class TestRouter extends mercury_event_emitter_1.AbstractEventEmitter {
|
|
|
85
85
|
authenticator: heartwood_view_controllers_1.AuthenticatorImpl.getInstance(),
|
|
86
86
|
args,
|
|
87
87
|
locale: this.locale,
|
|
88
|
-
authorizer:
|
|
88
|
+
authorizer: FakeAuthorizer_1.default.getInstance(),
|
|
89
89
|
scope: this.scope,
|
|
90
90
|
themes: this.themes,
|
|
91
91
|
};
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@sprucelabs/spruce-test-fixtures"
|
|
14
14
|
]
|
|
15
15
|
},
|
|
16
|
-
"version": "52.3.
|
|
16
|
+
"version": "52.3.23",
|
|
17
17
|
"files": [
|
|
18
18
|
"build/**/*",
|
|
19
19
|
"!build/__tests__",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@sprucelabs/schema": "^28.5.81",
|
|
72
72
|
"@sprucelabs/spruce-core-schemas": "^35.1.82",
|
|
73
73
|
"@sprucelabs/spruce-event-utils": "^30.0.12",
|
|
74
|
-
"@sprucelabs/spruce-skill-booter": "^52.3.
|
|
74
|
+
"@sprucelabs/spruce-skill-booter": "^52.3.23",
|
|
75
75
|
"@sprucelabs/spruce-skill-utils": "^28.1.10",
|
|
76
76
|
"@sprucelabs/test-utils": "^3.2.69",
|
|
77
77
|
"dotenv": "^16.0.3",
|
|
@@ -131,5 +131,5 @@
|
|
|
131
131
|
]
|
|
132
132
|
]
|
|
133
133
|
},
|
|
134
|
-
"gitHead": "
|
|
134
|
+
"gitHead": "38359eb0502bf763739da3e4a3505dd7cc587e64"
|
|
135
135
|
}
|