@sprucelabs/spruce-invite-utils 3.3.1 → 3.4.0

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.
@@ -1,7 +1,11 @@
1
+ import { PromptForLoginAndConfirmOptions } from '../../loggingInAndConfirmingJoin/LoginAndConfirmJoinController';
1
2
  export default class LoginAndConfirmTestFixture {
2
3
  private static hitCount;
4
+ private static wasBeforeEachCalled;
5
+ static lastPromptOptions?: PromptForLoginAndConfirmOptions;
3
6
  static beforeEach(): void;
4
7
  static getHitCount(): number;
8
+ private static assertBeforeEachWasCalled;
5
9
  static setResponse(r: boolean): void;
6
10
  private static setClass;
7
11
  }
@@ -3,16 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const test_1 = require("@sprucelabs/test");
6
7
  const LoginAndConfirmJoinController_1 = __importDefault(require("../../loggingInAndConfirmingJoin/LoginAndConfirmJoinController"));
7
8
  class LoginAndConfirmTestFixture {
8
9
  static beforeEach() {
9
10
  this.setClass(CountingLoginAndConfirmController);
10
11
  this.hitCount = 0;
12
+ this.wasBeforeEachCalled = true;
11
13
  }
12
14
  static getHitCount() {
15
+ this.assertBeforeEachWasCalled();
13
16
  return this.hitCount;
14
17
  }
18
+ static assertBeforeEachWasCalled() {
19
+ test_1.assert.isTrue(this.wasBeforeEachCalled, `Make sure you call 'LoginAndConfirmTestFixture.beforeEach()' in your test!`);
20
+ }
15
21
  static setResponse(r) {
22
+ this.assertBeforeEachWasCalled();
16
23
  const Class = r
17
24
  ? PassingLoginAndConfirmController
18
25
  : FailingLoginAndConfirmController;
@@ -24,10 +31,12 @@ class LoginAndConfirmTestFixture {
24
31
  }
25
32
  exports.default = LoginAndConfirmTestFixture;
26
33
  LoginAndConfirmTestFixture.hitCount = 0;
34
+ LoginAndConfirmTestFixture.wasBeforeEachCalled = false;
27
35
  class CountingLoginAndConfirmController {
28
- async promptForLoginAndConfirmJoin() {
36
+ async promptForLoginAndConfirmJoin(options) {
29
37
  //@ts-ignore
30
38
  LoginAndConfirmTestFixture.hitCount++;
39
+ LoginAndConfirmTestFixture.lastPromptOptions = options;
31
40
  return true;
32
41
  }
33
42
  }
@@ -1,7 +1,11 @@
1
+ import { PromptForLoginAndConfirmOptions } from '../../loggingInAndConfirmingJoin/LoginAndConfirmJoinController';
1
2
  export default class LoginAndConfirmTestFixture {
2
3
  private static hitCount;
4
+ private static wasBeforeEachCalled;
5
+ static lastPromptOptions?: PromptForLoginAndConfirmOptions;
3
6
  static beforeEach(): void;
4
7
  static getHitCount(): number;
8
+ private static assertBeforeEachWasCalled;
5
9
  static setResponse(r: boolean): void;
6
10
  private static setClass;
7
11
  }
@@ -7,16 +7,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { assert } from '@sprucelabs/test';
10
11
  import LoginAndConfirmJoinControllerImpl from '../../loggingInAndConfirmingJoin/LoginAndConfirmJoinController.js';
11
12
  export default class LoginAndConfirmTestFixture {
12
13
  static beforeEach() {
13
14
  this.setClass(CountingLoginAndConfirmController);
14
15
  this.hitCount = 0;
16
+ this.wasBeforeEachCalled = true;
15
17
  }
16
18
  static getHitCount() {
19
+ this.assertBeforeEachWasCalled();
17
20
  return this.hitCount;
18
21
  }
22
+ static assertBeforeEachWasCalled() {
23
+ assert.isTrue(this.wasBeforeEachCalled, `Make sure you call 'LoginAndConfirmTestFixture.beforeEach()' in your test!`);
24
+ }
19
25
  static setResponse(r) {
26
+ this.assertBeforeEachWasCalled();
20
27
  const Class = r
21
28
  ? PassingLoginAndConfirmController
22
29
  : FailingLoginAndConfirmController;
@@ -27,11 +34,13 @@ export default class LoginAndConfirmTestFixture {
27
34
  }
28
35
  }
29
36
  LoginAndConfirmTestFixture.hitCount = 0;
37
+ LoginAndConfirmTestFixture.wasBeforeEachCalled = false;
30
38
  class CountingLoginAndConfirmController {
31
- promptForLoginAndConfirmJoin() {
39
+ promptForLoginAndConfirmJoin(options) {
32
40
  return __awaiter(this, void 0, void 0, function* () {
33
41
  //@ts-ignore
34
42
  LoginAndConfirmTestFixture.hitCount++;
43
+ LoginAndConfirmTestFixture.lastPromptOptions = options;
35
44
  return true;
36
45
  });
37
46
  }
@@ -1,8 +1,5 @@
1
- import { Authenticator, CardViewControllerImpl, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
1
+ import { Authenticator, CardViewControllerImpl, SpruceSchemas, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { MercuryClient } from '@sprucelabs/mercury-client';
3
- export interface LoginAndConfirmJoinController {
4
- promptForLoginAndConfirmJoin(): Promise<boolean>;
5
- }
6
3
  export default class LoginAndConfirmJoinControllerImpl implements LoginAndConfirmJoinController {
7
4
  private views;
8
5
  protected vc: CardViewControllerImpl;
@@ -13,10 +10,11 @@ export default class LoginAndConfirmJoinControllerImpl implements LoginAndConfir
13
10
  private connectToApi;
14
11
  private client;
15
12
  private locationId?;
13
+ private confirmJoinContext?;
16
14
  protected constructor(options: LoginAndConfirmJoinOptions);
17
15
  static setClass(Class?: new () => LoginAndConfirmJoinController): void;
18
16
  static Controller(options: LoginAndConfirmJoinOptions): LoginAndConfirmJoinController;
19
- promptForLoginAndConfirmJoin(): Promise<boolean>;
17
+ promptForLoginAndConfirmJoin(options?: PromptForLoginAndConfirmOptions): Promise<boolean>;
20
18
  private listRoles;
21
19
  private confirmTheJoin;
22
20
  private promptForLogin;
@@ -24,11 +22,18 @@ export default class LoginAndConfirmJoinControllerImpl implements LoginAndConfir
24
22
  }
25
23
  export interface LoginAndConfirmJoinOptions {
26
24
  authenticator: Authenticator;
27
- views: Pick<ViewControllerFactory, 'Controller' | 'setController'>;
25
+ views: Pick<ViewControllerFactory, 'Controller' | 'setController' | 'hasController'>;
28
26
  organizationId: string;
29
27
  locationId?: string;
30
28
  connectToApi: ConnectToApi;
31
29
  }
32
30
  export declare type LoginAndConfirmJoinConstructor = new () => LoginAndConfirmJoinController;
33
31
  declare type ConnectToApi = () => Promise<MercuryClient>;
32
+ export declare type InviteViewContext = SpruceSchemas.Invite.v2021_12_16.InviteViewContext;
33
+ export interface PromptForLoginAndConfirmOptions {
34
+ confirmJoinViewContext?: InviteViewContext;
35
+ }
36
+ export interface LoginAndConfirmJoinController {
37
+ promptForLoginAndConfirmJoin(options?: PromptForLoginAndConfirmOptions): Promise<boolean>;
38
+ }
34
39
  export {};
@@ -24,18 +24,21 @@ export default class LoginAndConfirmJoinControllerImpl {
24
24
  }
25
25
  static Controller(options) {
26
26
  var _a;
27
- assertOptions(options, [
27
+ const { views } = assertOptions(options, [
28
28
  'authenticator',
29
29
  'views',
30
30
  'organizationId',
31
31
  'connectToApi',
32
32
  ]);
33
- options.views.setController('invite.confirm-join-card', ConfirmJoinCardViewController);
33
+ if (!views.hasController('invite.confirm-join-card')) {
34
+ views.setController('invite.confirm-join-card', ConfirmJoinCardViewController);
35
+ }
34
36
  return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(options);
35
37
  }
36
- promptForLoginAndConfirmJoin() {
38
+ promptForLoginAndConfirmJoin(options) {
37
39
  return __awaiter(this, void 0, void 0, function* () {
38
40
  this.client = yield this.connectToApi();
41
+ this.confirmJoinContext = options === null || options === void 0 ? void 0 : options.confirmJoinViewContext;
39
42
  if (this.authenticator.isLoggedIn()) {
40
43
  return true;
41
44
  }
@@ -79,7 +82,7 @@ export default class LoginAndConfirmJoinControllerImpl {
79
82
  onError: () => { },
80
83
  organizationId: this.organizationId,
81
84
  authenticator: this.authenticator,
82
- viewContext: {},
85
+ viewContext: Object.assign({}, this.confirmJoinContext),
83
86
  });
84
87
  yield confirmVc.load();
85
88
  yield this.renderInDialogAndWait(confirmVc.render());
@@ -1,8 +1,5 @@
1
- import { Authenticator, CardViewControllerImpl, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
1
+ import { Authenticator, CardViewControllerImpl, SpruceSchemas, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { MercuryClient } from '@sprucelabs/mercury-client';
3
- export interface LoginAndConfirmJoinController {
4
- promptForLoginAndConfirmJoin(): Promise<boolean>;
5
- }
6
3
  export default class LoginAndConfirmJoinControllerImpl implements LoginAndConfirmJoinController {
7
4
  private views;
8
5
  protected vc: CardViewControllerImpl;
@@ -13,10 +10,11 @@ export default class LoginAndConfirmJoinControllerImpl implements LoginAndConfir
13
10
  private connectToApi;
14
11
  private client;
15
12
  private locationId?;
13
+ private confirmJoinContext?;
16
14
  protected constructor(options: LoginAndConfirmJoinOptions);
17
15
  static setClass(Class?: new () => LoginAndConfirmJoinController): void;
18
16
  static Controller(options: LoginAndConfirmJoinOptions): LoginAndConfirmJoinController;
19
- promptForLoginAndConfirmJoin(): Promise<boolean>;
17
+ promptForLoginAndConfirmJoin(options?: PromptForLoginAndConfirmOptions): Promise<boolean>;
20
18
  private listRoles;
21
19
  private confirmTheJoin;
22
20
  private promptForLogin;
@@ -24,11 +22,18 @@ export default class LoginAndConfirmJoinControllerImpl implements LoginAndConfir
24
22
  }
25
23
  export interface LoginAndConfirmJoinOptions {
26
24
  authenticator: Authenticator;
27
- views: Pick<ViewControllerFactory, 'Controller' | 'setController'>;
25
+ views: Pick<ViewControllerFactory, 'Controller' | 'setController' | 'hasController'>;
28
26
  organizationId: string;
29
27
  locationId?: string;
30
28
  connectToApi: ConnectToApi;
31
29
  }
32
30
  export declare type LoginAndConfirmJoinConstructor = new () => LoginAndConfirmJoinController;
33
31
  declare type ConnectToApi = () => Promise<MercuryClient>;
32
+ export declare type InviteViewContext = SpruceSchemas.Invite.v2021_12_16.InviteViewContext;
33
+ export interface PromptForLoginAndConfirmOptions {
34
+ confirmJoinViewContext?: InviteViewContext;
35
+ }
36
+ export interface LoginAndConfirmJoinController {
37
+ promptForLoginAndConfirmJoin(options?: PromptForLoginAndConfirmOptions): Promise<boolean>;
38
+ }
34
39
  export {};
@@ -20,17 +20,20 @@ class LoginAndConfirmJoinControllerImpl {
20
20
  }
21
21
  static Controller(options) {
22
22
  var _a;
23
- (0, schema_1.assertOptions)(options, [
23
+ const { views } = (0, schema_1.assertOptions)(options, [
24
24
  'authenticator',
25
25
  'views',
26
26
  'organizationId',
27
27
  'connectToApi',
28
28
  ]);
29
- options.views.setController('invite.confirm-join-card', ConfirmJoinCard_vc_1.default);
29
+ if (!views.hasController('invite.confirm-join-card')) {
30
+ views.setController('invite.confirm-join-card', ConfirmJoinCard_vc_1.default);
31
+ }
30
32
  return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(options);
31
33
  }
32
- async promptForLoginAndConfirmJoin() {
34
+ async promptForLoginAndConfirmJoin(options) {
33
35
  this.client = await this.connectToApi();
36
+ this.confirmJoinContext = options === null || options === void 0 ? void 0 : options.confirmJoinViewContext;
34
37
  if (this.authenticator.isLoggedIn()) {
35
38
  return true;
36
39
  }
@@ -70,7 +73,7 @@ class LoginAndConfirmJoinControllerImpl {
70
73
  onError: () => { },
71
74
  organizationId: this.organizationId,
72
75
  authenticator: this.authenticator,
73
- viewContext: {},
76
+ viewContext: Object.assign({}, this.confirmJoinContext),
74
77
  });
75
78
  await confirmVc.load();
76
79
  await this.renderInDialogAndWait(confirmVc.render());
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-invite-utils",
3
3
  "description": "Invite Utilities",
4
- "version": "3.3.1",
4
+ "version": "3.4.0",
5
5
  "skill": {
6
6
  "namespace": "invite"
7
7
  },