@bevel-software/platform-core-frontend 0.26.0 → 0.28.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.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +87 -25
- package/src/core/ProductName.tsx +49 -0
- package/src/core/__tests__/ProductName.test.tsx +46 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
- package/src/core/__tests__/core-contributions.test.ts +16 -0
- package/src/core/core-contributions.ts +17 -0
- package/src/core/maker-url.ts +30 -0
- package/src/core/registry.ts +78 -1
- package/src/index.css +23 -5
- package/src/index.ts +5 -0
- package/src/lib/__tests__/latest-request.test.ts +48 -0
- package/src/lib/latest-request.ts +45 -0
- package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
- package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
- package/src/modules/access/api.ts +19 -3
- package/src/modules/access/components/ManageAccessDialog.tsx +61 -8
- package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
- package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
- package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
- package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
- package/src/modules/admin/services/roles.api.ts +14 -1
- package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
- package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
- package/src/modules/auth/components/LoginScreen.tsx +101 -73
- package/src/modules/auth/services/account.api.ts +59 -3
- package/src/modules/auth/services/sso.ts +30 -10
- package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
- package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
- package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
- package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
- package/src/modules/change-requests/services/change-requests.api.ts +15 -2
- package/src/modules/change-requests/utils/readFailure.ts +22 -0
- package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
- package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
- package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
- package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
- package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
- package/src/modules/embed/__tests__/mount.test.tsx +157 -0
- package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
- package/src/modules/embed/components/EmbedView.tsx +545 -0
- package/src/modules/embed/embed-config.ts +132 -0
- package/src/modules/embed/embed-host.ts +120 -0
- package/src/modules/embed/mount.tsx +80 -0
- package/src/modules/embed/services/embed-token.ts +22 -0
- package/src/modules/embed/services/embed.api.ts +158 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
- package/src/modules/git/branch-delete-menu-item.tsx +24 -0
- package/src/modules/git/components/BranchSwitcher.tsx +29 -5
- package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
- package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
- package/src/modules/git/components/PullNeededBanner.tsx +15 -49
- package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
- package/src/modules/git/index.ts +15 -0
- package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
- package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
- package/src/modules/git/services/error-messages.ts +58 -1
- package/src/modules/git/services/pull-failure.ts +68 -0
- package/src/modules/git/state/branch-delete-confirm.ts +46 -0
- package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
- package/src/modules/layout/breakpoints.ts +8 -0
- package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
- package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
- package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
- package/src/modules/library/components/LibraryPage.tsx +22 -0
- package/src/modules/library/components/PluginExtras.tsx +23 -6
- package/src/modules/library/components/PluginPage.tsx +6 -1
- package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
- package/src/modules/library/services/plugins.api.ts +4 -1
- package/src/modules/library/state/plugins-revision.ts +28 -0
- package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
- package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
- package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +164 -0
- package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1458 -0
- package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +811 -0
- package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
- package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
- package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
- package/src/modules/onboarding/components/GetStartedColumn.tsx +670 -0
- package/src/modules/onboarding/components/InviteButton.tsx +139 -0
- package/src/modules/onboarding/components/InviteDialog.tsx +741 -0
- package/src/modules/onboarding/components/RootLanding.tsx +8 -24
- package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
- package/src/modules/onboarding/first-page-prompt.ts +123 -0
- package/src/modules/onboarding/invite-emails.ts +313 -0
- package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
- package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
- package/src/modules/onboarding/state/agent-connection.ts +167 -0
- package/src/modules/onboarding/state/invite-dialog.context.ts +35 -0
- package/src/modules/onboarding/state/invite-dialog.tsx +39 -0
- package/src/modules/onboarding/state/onboarding.ts +133 -59
- package/src/modules/onboarding/state/starter-packs.ts +169 -0
- package/src/modules/settings/settings-nav-items.tsx +8 -3
- package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
- package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
- package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
- package/src/modules/setup/__tests__/setup.test.tsx +56 -15
- package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
- package/src/modules/setup/components/SetupGate.tsx +46 -1
- package/src/modules/setup/components/SetupScreen.tsx +81 -84
- package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
- package/src/modules/setup/services/setup.api.ts +3 -3
- package/src/modules/setup/utils/suggested-branch.ts +27 -0
- package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
- package/src/modules/toolbar/commands/actions.tsx +330 -0
- package/src/modules/toolbar/commands/command-menu.ts +44 -0
- package/src/modules/toolbar/commands/useCommandActions.ts +71 -0
- package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +125 -22
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
- package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
- package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
- package/src/modules/toolbar/components/Toolbar.tsx +10 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +230 -52
- package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
- package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +864 -0
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
- package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
- package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
- package/src/modules/toolbar/search/rank.ts +111 -0
- package/src/modules/toolbar/search/sources.ts +169 -0
- package/src/modules/workflow/hooks/useFileLock.ts +10 -7
- package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
- package/src/modules/workflow/services/lock.api.ts +17 -2
- package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
- package/src/modules/workspace/components/EditorTabs.tsx +39 -15
- package/src/modules/workspace/components/FileExplorer.tsx +39 -6
- package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
- package/src/modules/workspace/components/FileRoute.tsx +12 -7
- package/src/modules/workspace/components/FileViewer.tsx +271 -74
- package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
- package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
- package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
- package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
- package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
- package/src/modules/workspace/components/renderers/index.ts +26 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
- package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
- package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
- package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
- package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
- package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
- package/src/modules/workspace/hooks/useCreatePage.ts +206 -0
- package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
- package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
- package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
- package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
- package/src/modules/workspace/routing/kb-routes.ts +66 -12
- package/src/modules/workspace/state/editable-page.ts +42 -0
- package/src/modules/workspace/state/workspace.context.ts +13 -4
- package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
- package/src/modules/workspace/utils/display-file-name.ts +102 -0
- package/src/modules/workspace/utils/fileTree.ts +49 -14
- package/src/modules/workspace/utils/treeConfirm.ts +15 -0
- package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
- package/src/shared/components/ConfirmProvider.tsx +156 -0
- package/src/shared/components/Dialog.tsx +7 -0
- package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
- package/src/shared/components/confirm-context.ts +94 -0
- package/src/shared/components/index.ts +3 -0
- package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
- package/src/modules/onboarding/welcome-state.ts +0 -36
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { isInvited, sendInvites, wasEmailed } from '../invite-emails';
|
|
3
|
+
|
|
4
|
+
/** Every invite promotion is sent `ifActive`: the server refuses a switched-off account at the write. */
|
|
5
|
+
const ACTIVE = { ifActive: true };
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `sendInvites` with and without a starting password: who gets it, who keeps
|
|
9
|
+
* their own, who is left alone, and that a send with a password never writes
|
|
10
|
+
* blind when the account list cannot be read (the server's account write
|
|
11
|
+
* replaces a stored password).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const PW = 'welcome-to-acme';
|
|
15
|
+
/** How a starting password is sent: the server never writes it over one of the account's own. */
|
|
16
|
+
const KEEP = { keepExistingPassword: true };
|
|
17
|
+
|
|
18
|
+
function makeApi(accounts: { email: string; hasPassword?: boolean; isEnvAdmin?: boolean; deactivatedAt?: string | null }[] | Error) {
|
|
19
|
+
return {
|
|
20
|
+
listAccounts: vi.fn(async () => {
|
|
21
|
+
if (accounts instanceof Error) throw accounts;
|
|
22
|
+
return accounts;
|
|
23
|
+
}),
|
|
24
|
+
createAccount: vi.fn<
|
|
25
|
+
(
|
|
26
|
+
email: string,
|
|
27
|
+
name: string,
|
|
28
|
+
password?: string,
|
|
29
|
+
options?: { keepExistingPassword?: boolean },
|
|
30
|
+
) => Promise<{ passwordSet?: boolean; deactivated?: boolean; notified?: string[] } | void>
|
|
31
|
+
>(async () => ({ passwordSet: true })),
|
|
32
|
+
addMember: vi.fn(async () => []),
|
|
33
|
+
fetchRoles: vi.fn(async () => [{ canonical: 'admin', members: ['boss@acme.com'] }]),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let api: ReturnType<typeof makeApi>;
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
api = makeApi([
|
|
40
|
+
{ email: 'nopw@acme.com', hasPassword: false },
|
|
41
|
+
{ email: 'own@acme.com', hasPassword: true },
|
|
42
|
+
{ email: 'env@acme.com', hasPassword: false, isEnvAdmin: true },
|
|
43
|
+
{ email: 'off@acme.com', hasPassword: false, deactivatedAt: '2026-09-01T00:00:00Z' },
|
|
44
|
+
]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('sendInvites with a starting password', () => {
|
|
48
|
+
it('creates new accounts with it and completes an existing one that has none', async () => {
|
|
49
|
+
const result = await sendInvites(['new@acme.com', 'nopw@acme.com'], 'member', api, { password: PW });
|
|
50
|
+
expect(api.createAccount.mock.calls).toEqual([
|
|
51
|
+
['new@acme.com', '', PW, KEEP],
|
|
52
|
+
['nopw@acme.com', '', PW, KEEP],
|
|
53
|
+
]);
|
|
54
|
+
expect(result).toEqual({
|
|
55
|
+
status: 'sent',
|
|
56
|
+
outcomes: [
|
|
57
|
+
{ email: 'new@acme.com', status: 'created', role: 'member', passwordSet: true },
|
|
58
|
+
{ email: 'nopw@acme.com', status: 'existing', passwordSet: true },
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('never writes an account with its own password, the deployment admin, or a switched-off one', async () => {
|
|
64
|
+
const result = await sendInvites(['own@acme.com', 'env@acme.com', 'off@acme.com'], 'member', api, { password: PW });
|
|
65
|
+
expect(api.createAccount).not.toHaveBeenCalled();
|
|
66
|
+
expect(result).toEqual({
|
|
67
|
+
status: 'sent',
|
|
68
|
+
outcomes: [
|
|
69
|
+
{ email: 'own@acme.com', status: 'existing', hasOwnPassword: true },
|
|
70
|
+
{ email: 'env@acme.com', status: 'existing', hasOwnPassword: true },
|
|
71
|
+
{ email: 'off@acme.com', status: 'existing', deactivated: true },
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('still makes Admin invites admins, after the password', async () => {
|
|
77
|
+
await sendInvites(['new@acme.com', 'nopw@acme.com'], 'admin', api, { password: PW });
|
|
78
|
+
expect(api.createAccount.mock.calls.map((c) => c[2])).toEqual([PW, PW]);
|
|
79
|
+
expect(api.addMember.mock.calls).toEqual([
|
|
80
|
+
['admin', 'new@acme.com', ACTIVE],
|
|
81
|
+
['admin', 'nopw@acme.com', ACTIVE],
|
|
82
|
+
]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('leaves an existing account as it was when setting the password fails, with the reason', async () => {
|
|
86
|
+
api.createAccount.mockRejectedValueOnce(new Error('Password too common'));
|
|
87
|
+
const result = await sendInvites(['nopw@acme.com'], 'admin', api, { password: PW });
|
|
88
|
+
expect(result).toEqual({
|
|
89
|
+
status: 'sent',
|
|
90
|
+
outcomes: [{ email: 'nopw@acme.com', status: 'existing', passwordError: 'Password too common' }],
|
|
91
|
+
});
|
|
92
|
+
expect(api.addMember).not.toHaveBeenCalled();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('sends nothing at all when the account list cannot be read', async () => {
|
|
96
|
+
api = makeApi(new Error('down'));
|
|
97
|
+
const result = await sendInvites(['new@acme.com'], 'admin', api, { password: PW });
|
|
98
|
+
expect(result).toEqual({ status: 'accounts-unreadable' });
|
|
99
|
+
expect(api.createAccount).not.toHaveBeenCalled();
|
|
100
|
+
expect(api.addMember).not.toHaveBeenCalled();
|
|
101
|
+
expect(api.fetchRoles).not.toHaveBeenCalled();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('keeps a password the account set after the list was read: the server refused the write', async () => {
|
|
105
|
+
api.createAccount.mockResolvedValue({ passwordSet: false });
|
|
106
|
+
const result = await sendInvites(['nopw@acme.com', 'new@acme.com'], 'member', api, { password: PW });
|
|
107
|
+
expect(api.createAccount.mock.calls).toEqual([
|
|
108
|
+
['nopw@acme.com', '', PW, KEEP],
|
|
109
|
+
['new@acme.com', '', PW, KEEP],
|
|
110
|
+
]);
|
|
111
|
+
expect(result).toEqual({
|
|
112
|
+
status: 'sent',
|
|
113
|
+
outcomes: [
|
|
114
|
+
{ email: 'nopw@acme.com', status: 'existing', hasOwnPassword: true },
|
|
115
|
+
// Not on the list, but there with a password of its own by the time of the write.
|
|
116
|
+
{ email: 'new@acme.com', status: 'existing', hasOwnPassword: true },
|
|
117
|
+
],
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('reports an account switched off after the list was read as switched off, not invited', async () => {
|
|
122
|
+
api.createAccount.mockResolvedValue({ passwordSet: false, deactivated: true });
|
|
123
|
+
const result = await sendInvites(['nopw@acme.com', 'new@acme.com'], 'member', api, { password: PW });
|
|
124
|
+
expect(result).toEqual({
|
|
125
|
+
status: 'sent',
|
|
126
|
+
outcomes: [
|
|
127
|
+
{ email: 'nopw@acme.com', status: 'existing', deactivated: true },
|
|
128
|
+
{ email: 'new@acme.com', status: 'existing', deactivated: true },
|
|
129
|
+
],
|
|
130
|
+
});
|
|
131
|
+
if (result.status !== 'sent') throw new Error('not sent');
|
|
132
|
+
expect(result.outcomes.filter((o) => isInvited(o, true))).toEqual([]);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('does not make a switched-off account an Admin, listed so or switched off since the read', async () => {
|
|
136
|
+
// Listed as switched off: no password write and no promotion.
|
|
137
|
+
const listed = await sendInvites(['off@acme.com'], 'admin', api, { password: PW });
|
|
138
|
+
expect(listed).toEqual({ status: 'sent', outcomes: [{ email: 'off@acme.com', status: 'existing', deactivated: true }] });
|
|
139
|
+
// Switched off between the read and the write: the server left it, and so does the promotion.
|
|
140
|
+
api.createAccount.mockResolvedValue({ passwordSet: false, deactivated: true });
|
|
141
|
+
const since = await sendInvites(['nopw@acme.com', 'new@acme.com'], 'admin', api, { password: PW });
|
|
142
|
+
expect(since).toEqual({
|
|
143
|
+
status: 'sent',
|
|
144
|
+
outcomes: [
|
|
145
|
+
{ email: 'nopw@acme.com', status: 'existing', deactivated: true },
|
|
146
|
+
{ email: 'new@acme.com', status: 'existing', deactivated: true },
|
|
147
|
+
],
|
|
148
|
+
});
|
|
149
|
+
expect(api.addMember).not.toHaveBeenCalled();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('still promotes an account that got its own password since the read', async () => {
|
|
153
|
+
api.createAccount.mockResolvedValue({ passwordSet: false });
|
|
154
|
+
await sendInvites(['new@acme.com'], 'admin', api, { password: PW });
|
|
155
|
+
expect(api.addMember.mock.calls).toEqual([['admin', 'new@acme.com', ACTIVE]]);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('reports an account switched off between the read and the promotion as switched off, not an admin', async () => {
|
|
159
|
+
// The list says switched on and it has its own password, so nothing is
|
|
160
|
+
// written but the promotion — which the server refuses at the write.
|
|
161
|
+
api.addMember.mockRejectedValueOnce(Object.assign(new Error('This account is switched off'), { kind: 'deactivated' }));
|
|
162
|
+
const result = await sendInvites(['own@acme.com'], 'admin', api, { password: PW });
|
|
163
|
+
expect(api.addMember.mock.calls).toEqual([['admin', 'own@acme.com', ACTIVE]]);
|
|
164
|
+
expect(result).toEqual({
|
|
165
|
+
status: 'sent',
|
|
166
|
+
outcomes: [{ email: 'own@acme.com', status: 'existing', hasOwnPassword: true, deactivated: true }],
|
|
167
|
+
});
|
|
168
|
+
if (result.status !== 'sent') throw new Error('not sent');
|
|
169
|
+
expect(result.outcomes.filter((o) => isInvited(o, true))).toEqual([]);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('carries the password in no outcome', async () => {
|
|
173
|
+
const result = await sendInvites(['new@acme.com', 'nopw@acme.com', 'own@acme.com'], 'member', api, {
|
|
174
|
+
password: PW,
|
|
175
|
+
});
|
|
176
|
+
expect(JSON.stringify(result)).not.toContain(PW);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe('sendInvites without a password', () => {
|
|
181
|
+
it('gives no account one', async () => {
|
|
182
|
+
await sendInvites(['new@acme.com', 'nopw@acme.com'], 'member', api);
|
|
183
|
+
expect(api.createAccount.mock.calls).toEqual([['new@acme.com', '']]);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('treats every address as new when the list cannot be read, as before', async () => {
|
|
187
|
+
api = makeApi(new Error('down'));
|
|
188
|
+
const result = await sendInvites(['new@acme.com'], 'member', api);
|
|
189
|
+
expect(api.createAccount).toHaveBeenCalledWith('new@acme.com', '');
|
|
190
|
+
expect(result).toEqual({ status: 'sent', outcomes: [{ email: 'new@acme.com', status: 'created', role: 'member' }] });
|
|
191
|
+
});
|
|
192
|
+
it('leaves a switched-off account unchanged on an Admin invite: no promotion', async () => {
|
|
193
|
+
const result = await sendInvites(['off@acme.com'], 'admin', api);
|
|
194
|
+
expect(api.addMember).not.toHaveBeenCalled();
|
|
195
|
+
expect(result).toEqual({ status: 'sent', outcomes: [{ email: 'off@acme.com', status: 'existing', deactivated: true }] });
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe('sendInvites carries how the deployment told the person', () => {
|
|
200
|
+
it('a new account the server says was emailed carries `notified`; one nobody told does not', async () => {
|
|
201
|
+
api.createAccount
|
|
202
|
+
.mockResolvedValueOnce({ passwordSet: true, notified: ['email'] })
|
|
203
|
+
.mockResolvedValueOnce({ passwordSet: true, notified: [] });
|
|
204
|
+
const result = await sendInvites(['one@acme.com', 'two@acme.com'], 'member', api, { password: PW });
|
|
205
|
+
expect(result).toEqual({
|
|
206
|
+
status: 'sent',
|
|
207
|
+
outcomes: [
|
|
208
|
+
{ email: 'one@acme.com', status: 'created', role: 'member', passwordSet: true, notified: ['email'] },
|
|
209
|
+
{ email: 'two@acme.com', status: 'created', role: 'member', passwordSet: true },
|
|
210
|
+
],
|
|
211
|
+
});
|
|
212
|
+
expect(wasEmailed(result.status === 'sent' ? result.outcomes[0]! : failedOutcome)).toBe(true);
|
|
213
|
+
expect(wasEmailed(result.status === 'sent' ? result.outcomes[1]! : failedOutcome)).toBe(false);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('without a password too, and only for a NEW account: an existing one that got a password was not invited', async () => {
|
|
217
|
+
api.createAccount.mockResolvedValue({ notified: ['email'] });
|
|
218
|
+
const result = await sendInvites(['new@acme.com'], 'member', api);
|
|
219
|
+
expect(result).toEqual({
|
|
220
|
+
status: 'sent',
|
|
221
|
+
outcomes: [{ email: 'new@acme.com', status: 'created', role: 'member', notified: ['email'] }],
|
|
222
|
+
});
|
|
223
|
+
// The server answers `notified` for a new account only; an existing
|
|
224
|
+
// account's password write never carries it onto the row.
|
|
225
|
+
api.createAccount.mockResolvedValue({ passwordSet: true, notified: ['email'] });
|
|
226
|
+
const existing = await sendInvites(['nopw@acme.com'], 'member', api, { password: PW });
|
|
227
|
+
expect(existing).toEqual({
|
|
228
|
+
status: 'sent',
|
|
229
|
+
outcomes: [{ email: 'nopw@acme.com', status: 'existing', passwordSet: true }],
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const failedOutcome = { email: 'x@acme.com', status: 'error' as const, message: 'never' };
|
|
235
|
+
|
|
236
|
+
describe('isInvited', () => {
|
|
237
|
+
const failed = { email: 'nopw@acme.com', status: 'existing' as const, passwordError: 'Password too common' };
|
|
238
|
+
it('does not count an account whose password could not be set, without single sign-on', () => {
|
|
239
|
+
expect(isInvited(failed)).toBe(false);
|
|
240
|
+
});
|
|
241
|
+
it('counts it with single sign-on: it can still sign in that way', () => {
|
|
242
|
+
expect(isInvited(failed, true)).toBe(true);
|
|
243
|
+
});
|
|
244
|
+
it('never counts a switched-off account', () => {
|
|
245
|
+
expect(isInvited({ email: 'off@acme.com', status: 'existing', deactivated: true }, true)).toBe(false);
|
|
246
|
+
});
|
|
247
|
+
});
|