@jskit-ai/workspaces-core 0.2.57 → 0.2.59
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/CHANGELOG.md +8 -0
- package/locales/en.json +11 -2
- package/migrations/workspaces_core_memberships_accepted_invite.cjs +22 -0
- package/migrations/workspaces_core_settings_invites_require_same_email.cjs +20 -0
- package/package.json +9 -9
- package/patterns/workspace-server/PATTERN.md +26 -6
- package/src/server/WorkspacesFeature.js +1 -0
- package/src/server/WorkspacesIntegrationsProvider.js +2 -2
- package/src/server/common/repositories/workspaceInvitesRepository.js +21 -9
- package/src/server/common/repositories/workspaceMemberPagesRepository.js +12 -5
- package/src/server/common/repositories/workspaceMembershipsRepository.js +38 -8
- package/src/server/common/repositories/workspacesRepository.js +18 -0
- package/src/server/common/services/workspaceDirectoryService.js +47 -10
- package/src/server/common/services/workspaceMemberContext.js +3 -3
- package/src/server/support/workspaceInvitationsPolicy.js +5 -1
- package/src/server/types.js +24 -2
- package/src/server/workspaceMembers/appEnvironmentInviteMailer.js +26 -2
- package/src/server/workspaceMembers/defaultWorkspaceInviteEmail.js +1 -1
- package/src/server/workspaceMembers/workspaceMembersService.js +1 -0
- package/src/server/workspacePendingInvitations/inviterNotice.js +75 -0
- package/src/server/workspacePendingInvitations/workspacePendingInvitationsService.js +130 -26
- package/src/server/workspaceSettings/workspaceSettingsRepository.js +16 -4
- package/src/server/workspaceSettings/workspaceSettingsService.js +6 -1
- package/src/server/workspacesRuntime.js +16 -2
- package/src/shared/resources/workspaceMembersResource.js +13 -1
- package/src/shared/resources/workspaceMembershipsResource.js +11 -1
- package/src/shared/resources/workspacePendingInvitationsResource.js +2 -0
- package/src/shared/resources/workspaceSettingsResource.js +24 -2
- package/src/shared/tenancyProfile.js +15 -2
- package/test/appEnvironmentInviteMailer.test.js +33 -0
- package/test/featureRuntime.test.js +9 -1
- package/test/inviterNotice.test.js +66 -0
- package/test/repositories.integration.test.js +16 -19
- package/test/repositoryContracts.test.js +1 -0
- package/test/roleLabels.test.js +7 -2
- package/test/support/indexesByUserCases.js +2 -8
- package/test/support/invitationTransactions.js +14 -4
- package/test/support/mysqlWorkspaces.js +8 -9
- package/test/support/transferOwnershipCases.js +3 -9
- package/test/support/workspacesMigrations.js +23 -0
- package/test/tenancyProfile.test.js +16 -0
- package/test/workspaceDirectoryService.mysql.test.js +78 -3
- package/test/workspaceInvitationsPolicy.test.js +11 -0
- package/test/workspaceMemberListRoutes.test.js +10 -3
- package/test/workspaceMembersService.mysql.test.js +3 -3
- package/test/workspacePendingInvitationsService.mysql.test.js +94 -8
- package/test/workspacePendingInvitationsService.test.js +231 -5
- package/test/workspaceRecords.test.js +1 -0
- package/test/workspaceRecordsFeature.test.js +2 -7
- package/test/workspaceRequestContextQueries.test.js +51 -10
- package/test/workspaceService.test.js +1 -1
- package/test/workspaceSettingsService.test.js +30 -5
|
@@ -14,6 +14,7 @@ import { createWorkspaceMemberContexts } from "./common/services/workspaceMember
|
|
|
14
14
|
import { createWorkspacesServerI18n } from "./i18n.js";
|
|
15
15
|
import { createWorkspaceInviteUrlBuilder } from "./workspaceMembers/workspaceInviteUrls.js";
|
|
16
16
|
import { createService as createWorkspaceMembersService } from "./workspaceMembers/workspaceMembersService.js";
|
|
17
|
+
import { createInviterNotice } from "./workspacePendingInvitations/inviterNotice.js";
|
|
17
18
|
import { createService as createWorkspacePendingInvitationsService } from "./workspacePendingInvitations/workspacePendingInvitationsService.js";
|
|
18
19
|
import { createRepository as createWorkspaceSettingsRepository } from "./workspaceSettings/workspaceSettingsRepository.js";
|
|
19
20
|
import { createService as createWorkspaceSettingsService } from "./workspaceSettings/workspaceSettingsService.js";
|
|
@@ -101,6 +102,10 @@ function createWorkspaceDirectory({
|
|
|
101
102
|
config?.workspaceSettings?.defaults?.invitesEnabled,
|
|
102
103
|
"runtime.config.workspaceSettings.defaults.invitesEnabled"
|
|
103
104
|
),
|
|
105
|
+
defaultInvitesRequireSameEmail: requireBoolean(
|
|
106
|
+
config?.workspaceSettings?.defaults?.invitesRequireSameEmail ?? false,
|
|
107
|
+
"runtime.config.workspaceSettings.defaults.invitesRequireSameEmail"
|
|
108
|
+
),
|
|
104
109
|
defaultColorSettings: requireWorkspaceColorDefaults(config?.workspaceSettings?.defaults)
|
|
105
110
|
});
|
|
106
111
|
const workspaceService = createWorkspaceService({
|
|
@@ -133,6 +138,7 @@ function createWorkspaceDirectory({
|
|
|
133
138
|
* @param {import("./types.js").WorkspaceInviteMailer} dependencies.inviteMailer
|
|
134
139
|
* @param {import("./types.js").WorkspaceInviteEmailTemplate} dependencies.inviteEmailTemplate
|
|
135
140
|
* @param {import("./types.js").WorkspaceInviteAcceptanceParticipant} dependencies.inviteAcceptanceParticipant
|
|
141
|
+
* @param {import("@jskit-ai/kernel/server/types").RuntimeLogger} dependencies.logger
|
|
136
142
|
* @param {import("./types.js").PersonalWorkspaceName} dependencies.personalWorkspaceName
|
|
137
143
|
* @param {import("./types.js").WorkspacesResources} dependencies.resources The handles of the tables `workspaces.core` owns.
|
|
138
144
|
* @param {import("@jskit-ai/users-core/server/types").UsersProfiles} dependencies.userProfiles
|
|
@@ -148,6 +154,7 @@ function createWorkspacesRuntime({
|
|
|
148
154
|
inviteMailer,
|
|
149
155
|
inviteEmailTemplate,
|
|
150
156
|
inviteAcceptanceParticipant,
|
|
157
|
+
logger,
|
|
151
158
|
personalWorkspaceName,
|
|
152
159
|
resources,
|
|
153
160
|
userProfiles,
|
|
@@ -168,6 +175,7 @@ function createWorkspacesRuntime({
|
|
|
168
175
|
const { tenancyProfile, roleCatalog, workspaceSettingsRepository, workspaceService } = directory;
|
|
169
176
|
const invitationsPolicy = resolveWorkspaceInvitationsPolicy({ appConfig: config, tenancyProfile });
|
|
170
177
|
const invitationsEnabled = invitationsPolicy.enabled === true;
|
|
178
|
+
const i18n = createWorkspacesServerI18n({ appRoot });
|
|
171
179
|
const workspaceInvitesRepository = createWorkspaceInvitesRepository({
|
|
172
180
|
workspaceInvites: resources.workspaceInvites,
|
|
173
181
|
workspaces: workspacesRepository
|
|
@@ -175,13 +183,18 @@ function createWorkspacesRuntime({
|
|
|
175
183
|
const workspacePendingInvitationsService = createWorkspacePendingInvitationsService({
|
|
176
184
|
workspaceInvitesRepository,
|
|
177
185
|
workspaceMembershipsRepository,
|
|
186
|
+
workspacesRepository,
|
|
187
|
+
workspaceSettingsRepository,
|
|
178
188
|
roleCatalog,
|
|
179
|
-
acceptanceParticipant: inviteAcceptanceParticipant
|
|
189
|
+
acceptanceParticipant: inviteAcceptanceParticipant,
|
|
190
|
+
invitationsAnyAccount: invitationsPolicy.anyAccount,
|
|
191
|
+
notifyInviter: createInviterNotice({ inviteMailer, userProfiles, userSettings, i18n, logger })
|
|
180
192
|
});
|
|
181
193
|
const workspaceMembersService = createWorkspaceMembersService({
|
|
182
194
|
workspaceMembershipsRepository,
|
|
183
195
|
workspaceMemberPagesRepository: createWorkspaceMemberPagesRepository({
|
|
184
196
|
workspaceMemberships: resources.workspaceMemberships,
|
|
197
|
+
workspaceInvites: resources.workspaceInvites,
|
|
185
198
|
userProfiles
|
|
186
199
|
}),
|
|
187
200
|
workspaceInvitesRepository,
|
|
@@ -194,13 +207,14 @@ function createWorkspacesRuntime({
|
|
|
194
207
|
inviteUrlBuilder: createWorkspaceInviteUrlBuilder({ appConfig: config, env }),
|
|
195
208
|
workspaceInviteMailer: inviteMailer,
|
|
196
209
|
workspaceInviteEmailTemplate: inviteEmailTemplate,
|
|
197
|
-
i18n
|
|
210
|
+
i18n,
|
|
198
211
|
userProfilesRepository: userProfiles,
|
|
199
212
|
userSettingsRepository: userSettings
|
|
200
213
|
});
|
|
201
214
|
const workspaceSettingsService = createWorkspaceSettingsService({
|
|
202
215
|
workspaceSettingsRepository,
|
|
203
216
|
workspaceInvitationsEnabled: invitationsEnabled,
|
|
217
|
+
workspaceInvitationsAnyAccount: invitationsPolicy.anyAccount,
|
|
204
218
|
roleCatalog
|
|
205
219
|
});
|
|
206
220
|
|
|
@@ -10,7 +10,8 @@ const WORKSPACE_MEMBERS_FIELD_MESSAGES = deepFreeze({
|
|
|
10
10
|
inviteTokenRequired: { code: "workspaces.invite.tokenRequired", message: "Invite token is required." },
|
|
11
11
|
inviteTokenInvalid: { code: "workspaces.invite.tokenInvalid", message: "Invite token is invalid." },
|
|
12
12
|
decisionRequired: { code: "workspaces.invite.decisionRequired", message: "Decision is required." },
|
|
13
|
-
decisionInvalid: { code: "workspaces.invite.decisionInvalid", message: "Decision must be accept or refuse." }
|
|
13
|
+
decisionInvalid: { code: "workspaces.invite.decisionInvalid", message: "Decision must be accept or refuse." },
|
|
14
|
+
acceptAsInvalid: { code: "workspaces.invite.acceptAsInvalid", message: "acceptAs must be the signed-in account's email address." }
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
const workspaceSummaryOutputSchema = createSchema({
|
|
@@ -27,6 +28,8 @@ const memberSummaryOutputSchema = createSchema({
|
|
|
27
28
|
status: { type: "string", required: true, minLength: 1, maxLength: 64 },
|
|
28
29
|
displayName: { type: "string", required: true },
|
|
29
30
|
email: { type: "string", required: true, minLength: 1, maxLength: 255 },
|
|
31
|
+
// The address of the invitation the member joined through, when it is not their account's email; else "".
|
|
32
|
+
invitedEmail: { type: "string", required: true, maxLength: 255 },
|
|
30
33
|
isOwner: { type: "boolean", required: true }
|
|
31
34
|
});
|
|
32
35
|
|
|
@@ -217,6 +220,15 @@ const redeemInviteBodySchema = createSchema({
|
|
|
217
220
|
required: WORKSPACE_MEMBERS_FIELD_MESSAGES.decisionRequired,
|
|
218
221
|
default: WORKSPACE_MEMBERS_FIELD_MESSAGES.decisionInvalid
|
|
219
222
|
}
|
|
223
|
+
},
|
|
224
|
+
// The email of the account the person agreed to join as, when the invitation was sent to another address.
|
|
225
|
+
acceptAs: {
|
|
226
|
+
type: "string",
|
|
227
|
+
required: false,
|
|
228
|
+
maxLength: 255,
|
|
229
|
+
messages: {
|
|
230
|
+
default: WORKSPACE_MEMBERS_FIELD_MESSAGES.acceptAsInvalid
|
|
231
|
+
}
|
|
220
232
|
}
|
|
221
233
|
});
|
|
222
234
|
|
|
@@ -9,7 +9,8 @@ const workspaceMembershipsResource = defineTableResource({
|
|
|
9
9
|
ownership: "public",
|
|
10
10
|
foreignKeys: [
|
|
11
11
|
{ columns: ["workspaceId"], referencedTableName: "workspaces" },
|
|
12
|
-
{ columns: ["userId"], referencedTableName: "users" }
|
|
12
|
+
{ columns: ["userId"], referencedTableName: "users" },
|
|
13
|
+
{ columns: ["acceptedInviteId"], referencedTableName: "workspace_invites" }
|
|
13
14
|
],
|
|
14
15
|
searchSchema: {
|
|
15
16
|
workspace: { type: "id", actualField: "workspace_id", filterOperator: "=" },
|
|
@@ -52,6 +53,15 @@ const workspaceMembershipsResource = defineTableResource({
|
|
|
52
53
|
search: true,
|
|
53
54
|
setter: (value) => normalizeLowerText(value)
|
|
54
55
|
},
|
|
56
|
+
// The invitation the member last joined through: its address is the member's invitedEmail when it is not their
|
|
57
|
+
// account's. Null for an owner's membership, one an application added, and one older than the column.
|
|
58
|
+
acceptedInviteId: {
|
|
59
|
+
type: "id",
|
|
60
|
+
nullable: true,
|
|
61
|
+
belongsTo: "workspaceInvites",
|
|
62
|
+
as: "acceptedInvite",
|
|
63
|
+
storage: { column: "accepted_invite_id" }
|
|
64
|
+
},
|
|
55
65
|
createdAt: {
|
|
56
66
|
type: "dateTime",
|
|
57
67
|
storage: {
|
|
@@ -43,6 +43,8 @@ const invitationResolveOutputSchema = createSchema({
|
|
|
43
43
|
roleSid: { type: "string", required: true },
|
|
44
44
|
roleLabel: { type: "string", required: false },
|
|
45
45
|
expiresAt: { type: "string", required: false, nullable: true, minLength: 1 },
|
|
46
|
+
// False when any signed-in account may accept the invitation, confirming first when its email is another.
|
|
47
|
+
requiresSameEmail: { type: "boolean", required: true },
|
|
46
48
|
workspace: {
|
|
47
49
|
type: "object",
|
|
48
50
|
required: true,
|
|
@@ -85,10 +85,14 @@ const WORKSPACE_SETTINGS_FIELD_MESSAGES = deepFreeze({
|
|
|
85
85
|
invitesEnabledInvalid: {
|
|
86
86
|
code: "workspaces.settings.invitesEnabled.invalid",
|
|
87
87
|
message: "invitesEnabled must be a boolean."
|
|
88
|
+
},
|
|
89
|
+
invitesRequireSameEmailInvalid: {
|
|
90
|
+
code: "workspaces.settings.invitesRequireSameEmail.invalid",
|
|
91
|
+
message: "invitesRequireSameEmail must be a boolean."
|
|
88
92
|
}
|
|
89
93
|
});
|
|
90
94
|
|
|
91
|
-
const WORKSPACE_SETTINGS_FIELD_KEYS = deepFreeze([...WORKSPACE_SETTINGS_COLOR_FIELDS, "invitesEnabled"]);
|
|
95
|
+
const WORKSPACE_SETTINGS_FIELD_KEYS = deepFreeze([...WORKSPACE_SETTINGS_COLOR_FIELDS, "invitesEnabled", "invitesRequireSameEmail"]);
|
|
92
96
|
|
|
93
97
|
const workspaceSettingsBodySchema = createSchema({
|
|
94
98
|
lightPrimaryColor: {
|
|
@@ -195,6 +199,15 @@ const workspaceSettingsBodySchema = createSchema({
|
|
|
195
199
|
required: WORKSPACE_SETTINGS_FIELD_MESSAGES.invitesEnabledRequired,
|
|
196
200
|
default: WORKSPACE_SETTINGS_FIELD_MESSAGES.invitesEnabledInvalid
|
|
197
201
|
}
|
|
202
|
+
},
|
|
203
|
+
// Optional in every write, so a full write made before it existed stays valid; a new workspace takes the app's default.
|
|
204
|
+
invitesRequireSameEmail: {
|
|
205
|
+
type: "boolean",
|
|
206
|
+
required: false,
|
|
207
|
+
strictBoolean: true,
|
|
208
|
+
messages: {
|
|
209
|
+
default: WORKSPACE_SETTINGS_FIELD_MESSAGES.invitesRequireSameEmailInvalid
|
|
210
|
+
}
|
|
198
211
|
}
|
|
199
212
|
});
|
|
200
213
|
|
|
@@ -215,7 +228,11 @@ const workspaceSettingsViewSchema = createSchema({
|
|
|
215
228
|
darkSurfaceVariantColor: { type: "string", required: true, minLength: 7, maxLength: 7, pattern: "^#[0-9A-Fa-f]{6}$" },
|
|
216
229
|
invitesEnabled: { type: "boolean", required: true },
|
|
217
230
|
invitesAvailable: { type: "boolean", required: true },
|
|
218
|
-
invitesEffective: { type: "boolean", required: true }
|
|
231
|
+
invitesEffective: { type: "boolean", required: true },
|
|
232
|
+
// Whether only the invited address may accept the workspace's invitations: true whenever the app keeps that rule
|
|
233
|
+
// for every workspace (invitesAnyAccountAvailable false).
|
|
234
|
+
invitesRequireSameEmail: { type: "boolean", required: true },
|
|
235
|
+
invitesAnyAccountAvailable: { type: "boolean", required: true }
|
|
219
236
|
});
|
|
220
237
|
|
|
221
238
|
const workspaceSettingsOutputSchema = createSchema({
|
|
@@ -323,6 +340,11 @@ const workspaceSettingsResource = defineTableResource({
|
|
|
323
340
|
defaultTo: true,
|
|
324
341
|
storage: { column: "invites_enabled" }
|
|
325
342
|
},
|
|
343
|
+
invitesRequireSameEmail: {
|
|
344
|
+
type: "boolean",
|
|
345
|
+
defaultTo: false,
|
|
346
|
+
storage: { column: "invites_require_same_email" }
|
|
347
|
+
},
|
|
326
348
|
createdAt: {
|
|
327
349
|
type: "dateTime",
|
|
328
350
|
storage: {
|
|
@@ -9,6 +9,18 @@ import { isRecord } from "@jskit-ai/kernel/shared/support/normalize";
|
|
|
9
9
|
const WORKSPACE_SLUG_POLICY_NONE = "none";
|
|
10
10
|
const WORKSPACE_SLUG_POLICY_IMMUTABLE_USERNAME = "immutable_username";
|
|
11
11
|
const WORKSPACE_SLUG_POLICY_USER_SELECTED = "user_selected";
|
|
12
|
+
// autoProvision's third value: a personal workspace only for a person who is no active member of any workspace and
|
|
13
|
+
// whose sign-in carries no invitation they can use.
|
|
14
|
+
const WORKSPACE_AUTO_PROVISION_UNLESS_MEMBER = "unless-member";
|
|
15
|
+
|
|
16
|
+
function resolveAutoProvisionOverride(value) {
|
|
17
|
+
if (value === undefined || typeof value === "boolean" || value === WORKSPACE_AUTO_PROVISION_UNLESS_MEMBER) {
|
|
18
|
+
return value ?? null;
|
|
19
|
+
}
|
|
20
|
+
throw new TypeError(
|
|
21
|
+
`tenancyPolicy.workspace.autoProvision must be true, false or "${WORKSPACE_AUTO_PROVISION_UNLESS_MEMBER}". Received: ${String(value)}`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
12
24
|
|
|
13
25
|
function resolveWorkspacePolicyOverrides(appConfig = {}) {
|
|
14
26
|
const tenancyPolicy = isRecord(appConfig.tenancyPolicy) ? appConfig.tenancyPolicy : {};
|
|
@@ -16,7 +28,7 @@ function resolveWorkspacePolicyOverrides(appConfig = {}) {
|
|
|
16
28
|
|
|
17
29
|
return Object.freeze({
|
|
18
30
|
allowSelfCreate: typeof workspacePolicy.allowSelfCreate === "boolean" ? workspacePolicy.allowSelfCreate : null,
|
|
19
|
-
autoProvision:
|
|
31
|
+
autoProvision: resolveAutoProvisionOverride(workspacePolicy.autoProvision)
|
|
20
32
|
});
|
|
21
33
|
}
|
|
22
34
|
|
|
@@ -41,7 +53,7 @@ function resolveWorkspacePolicy(mode, overrides = {}) {
|
|
|
41
53
|
|
|
42
54
|
return Object.freeze({
|
|
43
55
|
enabled: true,
|
|
44
|
-
autoProvision: overrides.autoProvision
|
|
56
|
+
autoProvision: overrides.autoProvision ?? false,
|
|
45
57
|
allowSelfCreate: overrides.allowSelfCreate === true,
|
|
46
58
|
slugPolicy: WORKSPACE_SLUG_POLICY_USER_SELECTED
|
|
47
59
|
});
|
|
@@ -69,6 +81,7 @@ export {
|
|
|
69
81
|
WORKSPACE_SLUG_POLICY_NONE,
|
|
70
82
|
WORKSPACE_SLUG_POLICY_IMMUTABLE_USERNAME,
|
|
71
83
|
WORKSPACE_SLUG_POLICY_USER_SELECTED,
|
|
84
|
+
WORKSPACE_AUTO_PROVISION_UNLESS_MEMBER,
|
|
72
85
|
resolveTenancyProfile,
|
|
73
86
|
isWorkspacesTenancyMode
|
|
74
87
|
};
|
|
@@ -75,3 +75,36 @@ test("staging without STAGING_EMAIL_TO logs each invitation, and production send
|
|
|
75
75
|
assert.equal((await production.mailer.sendWorkspaceInvite(INVITE, {})).status, "sent");
|
|
76
76
|
assert.deepEqual(production.sent[0].invite, INVITE);
|
|
77
77
|
});
|
|
78
|
+
|
|
79
|
+
const NOTICE = Object.freeze({
|
|
80
|
+
inviteId: "7",
|
|
81
|
+
invite: { id: "7", email: "guest@example.com", roleSid: "member" },
|
|
82
|
+
inviter: { id: "2", email: "owner@example.com", displayName: "Olga" },
|
|
83
|
+
member: { id: "9", email: "other@example.com", displayName: "Otto" },
|
|
84
|
+
workspace: { id: "3", slug: "books", name: "Books" },
|
|
85
|
+
locale: "en",
|
|
86
|
+
message: Object.freeze({ subject: "Otto joined Books", text: "Otto accepted.", html: "<p>Otto accepted.</p>" })
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("the notice that another address accepted is sent as invitations are, only by a mailer that sends it", async () => {
|
|
90
|
+
const noticesSent = [];
|
|
91
|
+
const withNotice = createAppEnvironmentInviteMailer({
|
|
92
|
+
env: { ...SERVER_NODE_ENV, APP_ENV: "staging", STAGING_EMAIL_TO: "qa@example.test" },
|
|
93
|
+
logger: { info() {}, warn() {}, error() {}, debug() {} },
|
|
94
|
+
mailer: {
|
|
95
|
+
async sendWorkspaceInvite() {},
|
|
96
|
+
async sendInviteAcceptedByOtherAddress(notice, options) {
|
|
97
|
+
noticesSent.push({ notice, options });
|
|
98
|
+
return { status: "sent" };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
assert.deepEqual(await withNotice.sendInviteAcceptedByOtherAddress(NOTICE, { context: "c" }), { status: "sent" });
|
|
103
|
+
assert.equal(noticesSent.length, 1);
|
|
104
|
+
assert.equal(noticesSent[0].notice.inviter.email, "qa@example.test", "staging sends it to STAGING_EMAIL_TO");
|
|
105
|
+
assert.match(noticesSent[0].notice.message.text, /^Staging: this email was for owner@example\.com\./u);
|
|
106
|
+
assert.deepEqual(noticesSent[0].options, { context: "c" });
|
|
107
|
+
|
|
108
|
+
const { mailer: withoutNotice } = mailerIn({ APP_ENV: "development" });
|
|
109
|
+
assert.equal(Object.hasOwn(withoutNotice, "sendInviteAcceptedByOtherAddress"), false);
|
|
110
|
+
});
|
|
@@ -15,7 +15,7 @@ function runtimeConfig() {
|
|
|
15
15
|
return {
|
|
16
16
|
appPublicUrl: "http://localhost:5173",
|
|
17
17
|
tenancyMode: "workspaces",
|
|
18
|
-
tenancyPolicy: { workspace: { allowSelfCreate: true } },
|
|
18
|
+
tenancyPolicy: { workspace: { allowSelfCreate: true, autoProvision: "unless-member" } },
|
|
19
19
|
workspaceInvitations: { enabled: true },
|
|
20
20
|
workspaceMembers: { defaults: { inviteExpiresInMs: 86400000 } },
|
|
21
21
|
workspaceSettings: { defaults: { invitesEnabled: true } },
|
|
@@ -122,6 +122,14 @@ test("WorkspacesFeature assembles workspace behavior and explicit integrations",
|
|
|
122
122
|
assert.deepEqual(authExtensions.diagnostics().invitationContextResolverIds, ["workspaces.invitation"]);
|
|
123
123
|
assert.deepEqual(authExtensions.diagnostics().policyContextResolverIds, ["workspaces.policy"]);
|
|
124
124
|
assert.deepEqual(audienceContributors.map((entry) => entry.id), ["workspaces.memberships"]);
|
|
125
|
+
|
|
126
|
+
// Sign-in provisioning is told the invitation the sign-in carries: with "unless-member" one naming a workspace means
|
|
127
|
+
// no workspace of one's own, decided before any read (this database has no tables, so a read would fail).
|
|
128
|
+
const [provisioning] = usersExtensions.profileSyncLifecycleContributors();
|
|
129
|
+
const profile = { id: "5", email: "ivy@example.com", displayName: "Ivy" };
|
|
130
|
+
await provisioning.afterIdentityProfileSynced({ profile, created: true, invitation: { workspaceId: "3" }, options: {} });
|
|
131
|
+
await assert.rejects(provisioning.afterIdentityProfileSynced({ profile, created: true, invitation: null, options: {} }),
|
|
132
|
+
/workspace_memberships/u, "without an invitation it reads the person's memberships");
|
|
125
133
|
});
|
|
126
134
|
|
|
127
135
|
test("workspace realtime audiences are the actor's active memberships", async () => {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { createWorkspacesServerI18n } from "../src/server/i18n.js";
|
|
4
|
+
import { createInviterNotice } from "../src/server/workspacePendingInvitations/inviterNotice.js";
|
|
5
|
+
|
|
6
|
+
const ACCEPTANCE = Object.freeze({
|
|
7
|
+
invite: { id: "60", email: "invited@example.com", workspaceId: "1", invitedByUserId: "2", roleSid: "member", tokenHash: "secret" },
|
|
8
|
+
user: { id: "7", email: "other@example.com", displayName: "Olive" },
|
|
9
|
+
workspace: { id: "1", slug: "acme", name: "Acme <Labs>", ownerUserId: "2" }
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
function noticeWith({ mailer, profiles = { "2": { id: "2", email: "owner@example.com", displayName: "Oscar" } } }) {
|
|
13
|
+
const warnings = [];
|
|
14
|
+
const reads = [];
|
|
15
|
+
const notify = createInviterNotice({
|
|
16
|
+
inviteMailer: mailer,
|
|
17
|
+
userProfiles: { async findById(id) { reads.push(id); return profiles[id] ?? null; } },
|
|
18
|
+
userSettings: { async findByUserId() { return { locale: "en" }; } },
|
|
19
|
+
i18n: createWorkspacesServerI18n(),
|
|
20
|
+
logger: { warn: (details, message) => warnings.push({ details, message }) }
|
|
21
|
+
});
|
|
22
|
+
return { notify, warnings, reads };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
test("the inviter is sent what happened, with the facts and the email, and nothing secret", async () => {
|
|
26
|
+
const sent = [];
|
|
27
|
+
const { notify } = noticeWith({ mailer: { async sendWorkspaceInvite() {}, async sendInviteAcceptedByOtherAddress(notice, options) { sent.push({ notice, options }); } } });
|
|
28
|
+
|
|
29
|
+
await notify(ACCEPTANCE, { context: "request" });
|
|
30
|
+
|
|
31
|
+
assert.equal(sent.length, 1);
|
|
32
|
+
const { message, ...facts } = sent[0].notice;
|
|
33
|
+
assert.deepEqual(facts, {
|
|
34
|
+
inviteId: "60",
|
|
35
|
+
invite: { id: "60", email: "invited@example.com", roleSid: "member" },
|
|
36
|
+
inviter: { id: "2", email: "owner@example.com", displayName: "Oscar" },
|
|
37
|
+
member: { id: "7", email: "other@example.com", displayName: "Olive" },
|
|
38
|
+
workspace: { id: "1", slug: "acme", name: "Acme <Labs>" },
|
|
39
|
+
locale: "en"
|
|
40
|
+
});
|
|
41
|
+
assert.equal(message.subject, "Olive joined Acme <Labs>");
|
|
42
|
+
assert.equal(message.text,
|
|
43
|
+
"Olive accepted your invitation to Acme <Labs>, which you sent to invited@example.com. They joined with their account other@example.com." +
|
|
44
|
+
"\n\nIf you did not expect this, remove them from the workspace's members.");
|
|
45
|
+
assert.match(message.html, /<p>Olive accepted your invitation to Acme <Labs>,/u);
|
|
46
|
+
assert.deepEqual(sent[0].options, { context: "request" });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("a failed notice is logged and the acceptance stands; a mailer without it, or an inviter who is gone, sends nothing", async () => {
|
|
50
|
+
const failing = noticeWith({ mailer: { async sendInviteAcceptedByOtherAddress() { throw new Error("SMTP down"); } } });
|
|
51
|
+
await failing.notify(ACCEPTANCE);
|
|
52
|
+
assert.equal(failing.warnings.length, 1);
|
|
53
|
+
assert.equal(failing.warnings[0].message, "The inviter was not told that another address accepted their invitation.");
|
|
54
|
+
assert.deepEqual(failing.warnings[0].details.inviteId, "60");
|
|
55
|
+
|
|
56
|
+
const silent = noticeWith({ mailer: { async sendWorkspaceInvite() {} } });
|
|
57
|
+
await silent.notify(ACCEPTANCE);
|
|
58
|
+
assert.deepEqual(silent.reads, [], "no mailer method: nothing is read or sent");
|
|
59
|
+
|
|
60
|
+
const sent = [];
|
|
61
|
+
const gone = noticeWith({ mailer: { async sendInviteAcceptedByOtherAddress(notice) { sent.push(notice); } }, profiles: {} });
|
|
62
|
+
await gone.notify(ACCEPTANCE);
|
|
63
|
+
await gone.notify({ ...ACCEPTANCE, invite: { ...ACCEPTANCE.invite, invitedByUserId: null } });
|
|
64
|
+
assert.deepEqual(sent, []);
|
|
65
|
+
assert.deepEqual(gone.warnings, []);
|
|
66
|
+
});
|
|
@@ -12,12 +12,7 @@ import { userProfileTableResource } from "@jskit-ai/users-core/shared/resources/
|
|
|
12
12
|
import { userSettingsTableResource } from "@jskit-ai/users-core/shared/resources/userSettingsResource";
|
|
13
13
|
import { UsersExtensionsProvider } from "@jskit-ai/users-core/server/UsersExtensionsProvider";
|
|
14
14
|
import { UsersIdentityProvider } from "@jskit-ai/users-core/server/UsersIdentityProvider";
|
|
15
|
-
import
|
|
16
|
-
import usersUsername from "../../users-core/migrations/users_core_profile_username.cjs";
|
|
17
|
-
import usersUpdatedAt from "../../users-core/migrations/users_core_profile_updated_at.cjs";
|
|
18
|
-
import workspacesInitial from "../migrations/workspaces_core_initial.cjs";
|
|
19
|
-
import workspaceSettingsMigration from "../migrations/workspaces_core_workspace_settings_single_name_source.cjs";
|
|
20
|
-
import workspaceColorMigration from "../migrations/workspaces_core_workspaces_drop_color.cjs";
|
|
15
|
+
import { WORKSPACES_TEST_MIGRATIONS } from "./support/workspacesMigrations.js";
|
|
21
16
|
import { createWorkspaceRecords, createWorkspacesRuntime } from "../src/server/WorkspacesFeature.js";
|
|
22
17
|
import { ROLE_CONTEXT_TABLES, createStandaloneRoleContext } from "../src/server/standaloneRoleContext.js";
|
|
23
18
|
import { noInviteAcceptanceParticipant } from "../src/server/workspacePendingInvitations/noInviteAcceptanceParticipant.js";
|
|
@@ -38,7 +33,7 @@ import { createWorkspaceRoleCatalog } from "../src/shared/roles.js";
|
|
|
38
33
|
import { verifyInvitationTransactions } from "./support/invitationTransactions.js";
|
|
39
34
|
|
|
40
35
|
const TABLES = [
|
|
41
|
-
"
|
|
36
|
+
"workspace_memberships", "workspace_invites", "workspace_settings", "workspaces", "user_settings", "users"
|
|
42
37
|
];
|
|
43
38
|
const databaseUrl = process.env.JSKIT_REPOSITORY_TEST_DATABASE_URL;
|
|
44
39
|
|
|
@@ -122,9 +117,7 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
122
117
|
await knex.raw("PRAGMA foreign_keys = ON");
|
|
123
118
|
}
|
|
124
119
|
ownsTables = true;
|
|
125
|
-
for (const migration of
|
|
126
|
-
usersInitial, usersUsername, usersUpdatedAt, workspacesInitial, workspaceSettingsMigration, workspaceColorMigration
|
|
127
|
-
]) {
|
|
120
|
+
for (const migration of WORKSPACES_TEST_MIGRATIONS) {
|
|
128
121
|
await migration.up(knex);
|
|
129
122
|
}
|
|
130
123
|
// The tables owned as UsersIdentityProvider and WorkspacesFeature own them.
|
|
@@ -142,9 +135,13 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
142
135
|
workspaceTable = resources.workspaces;
|
|
143
136
|
({ workspaces, memberships } = createWorkspaceRecords(resources));
|
|
144
137
|
invites = createInvitesRepository({ workspaceInvites: resources.workspaceInvites, workspaces });
|
|
145
|
-
memberPages = createMemberPagesRepository({
|
|
138
|
+
memberPages = createMemberPagesRepository({
|
|
139
|
+
workspaceMemberships: resources.workspaceMemberships,
|
|
140
|
+
workspaceInvites: resources.workspaceInvites,
|
|
141
|
+
userProfiles: profiles
|
|
142
|
+
});
|
|
146
143
|
settings = createSettingsRepository({
|
|
147
|
-
workspaceSettings: resources.workspaceSettings, defaultInvitesEnabled: false, defaultColorSettings: {}
|
|
144
|
+
workspaceSettings: resources.workspaceSettings, defaultInvitesEnabled: false, defaultInvitesRequireSameEmail: false, defaultColorSettings: {}
|
|
148
145
|
});
|
|
149
146
|
});
|
|
150
147
|
|
|
@@ -530,7 +527,7 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
530
527
|
});
|
|
531
528
|
});
|
|
532
529
|
|
|
533
|
-
test("memberContext refuses a missing or deleted workspace, a non-member, a removed or inactive membership and a user id naming no one, as the member's request does", async () => {
|
|
530
|
+
test("memberContext refuses a missing or deleted workspace, a non-member, a removed or inactive membership and a user id naming no one, as the member's request does: each as not found", async () => {
|
|
534
531
|
const { directory, memberContext } = memberDirectory();
|
|
535
532
|
const owner = await createProfile("Ada");
|
|
536
533
|
const member = await createProfile("Grace");
|
|
@@ -550,7 +547,6 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
550
547
|
await workspaces.updateById(deleted.id, { deletedAt: new Date().toISOString() });
|
|
551
548
|
const system = { context: memberJobContext() };
|
|
552
549
|
const notFound = [404, "workspaces.workspace.notFound"];
|
|
553
|
-
const accessDenied = [403, "workspaces.workspace.accessDenied"];
|
|
554
550
|
const refuses = ([status, code], label) => (error) => {
|
|
555
551
|
assert.ok(error instanceof AppError, `${label}: ${error}`);
|
|
556
552
|
assert.deepEqual([error.status, error.code], [status, code], label);
|
|
@@ -561,10 +557,10 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
561
557
|
["a workspace id naming no workspace", { workspaceId: "999999", userId: member.id }, notFound, [member, "no-such-workspace"]],
|
|
562
558
|
["a deleted workspace's member", { workspaceId: deleted.id, userId: member.id }, notFound, [member, "gone"]],
|
|
563
559
|
["a deleted workspace's owner", { workspaceId: deleted.id, userId: owner.id }, notFound, [owner, "gone"]],
|
|
564
|
-
["a user who was never a member", { workspaceId: workspace.id, userId: outsider.id },
|
|
565
|
-
["a removed member", { workspaceId: workspace.id, userId: removed.id },
|
|
566
|
-
["an inactive member", { workspaceId: workspace.id, userId: inactive.id },
|
|
567
|
-
["a user id naming no one", { workspaceId: workspace.id, userId: "999999" },
|
|
560
|
+
["a user who was never a member", { workspaceId: workspace.id, userId: outsider.id }, notFound, [outsider, "team"]],
|
|
561
|
+
["a removed member", { workspaceId: workspace.id, userId: removed.id }, notFound, [removed, "team"]],
|
|
562
|
+
["an inactive member", { workspaceId: workspace.id, userId: inactive.id }, notFound, [inactive, "team"]],
|
|
563
|
+
["a user id naming no one", { workspaceId: workspace.id, userId: "999999" }, notFound, [{ id: "999999" }, "team"]]
|
|
568
564
|
];
|
|
569
565
|
for (const [label, asked, refusal, [user, slug]] of refusals) {
|
|
570
566
|
await assert.rejects(memberContext(asked, system), refuses(refusal, label));
|
|
@@ -693,7 +689,7 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
693
689
|
assert.equal(await memberships.findByWorkspaceIdAndUserId(workspace.id, outsider.id), null);
|
|
694
690
|
assert.equal((await memberships.findByWorkspaceIdAndUserId(workspace.id, member.id)).roleSid, "member");
|
|
695
691
|
assert.equal((await memberContext({ workspaceId: workspace.id, userId: member.id }, system)).membership.roleSid, "member");
|
|
696
|
-
await assert.rejects(memberContext({ workspaceId: workspace.id, userId: outsider.id }, system), (error) => error.status ===
|
|
692
|
+
await assert.rejects(memberContext({ workspaceId: workspace.id, userId: outsider.id }, system), (error) => error.status === 404);
|
|
697
693
|
|
|
698
694
|
// A workspace no request has opened has no settings yet, and the role context writes none, nor the owner's
|
|
699
695
|
// membership a member context ensures.
|
|
@@ -781,6 +777,7 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
781
777
|
inviteMailer: unconfiguredWorkspaceInviteMailer,
|
|
782
778
|
inviteEmailTemplate: renderDefaultWorkspaceInviteEmail,
|
|
783
779
|
inviteAcceptanceParticipant: noInviteAcceptanceParticipant,
|
|
780
|
+
logger: silentLogger,
|
|
784
781
|
personalWorkspaceName: buildWorkspaceName,
|
|
785
782
|
resources: workspaceResources,
|
|
786
783
|
userProfiles: profiles,
|
package/test/roleLabels.test.js
CHANGED
|
@@ -109,6 +109,7 @@ test("Members and Invitations response validation preserves labels and saved rol
|
|
|
109
109
|
test("Workspace Settings response validation preserves configured labels", async () => {
|
|
110
110
|
const service = createSettingsService({
|
|
111
111
|
workspaceInvitationsEnabled: true,
|
|
112
|
+
workspaceInvitationsAnyAccount: false,
|
|
112
113
|
roleCatalog: catalog,
|
|
113
114
|
workspaceSettingsRepository: {
|
|
114
115
|
async ensureForWorkspaceId() {
|
|
@@ -137,7 +138,11 @@ test("pending and resolved invitation responses derive labels while acceptance s
|
|
|
137
138
|
async withTransaction(options, work) { return work({ ...options, trx: {} }); },
|
|
138
139
|
async markAcceptedById() {}
|
|
139
140
|
},
|
|
140
|
-
workspaceMembershipsRepository: { async upsertMembership(_workspaceId, _userId, patch) { membership = patch; } }
|
|
141
|
+
workspaceMembershipsRepository: { async upsertMembership(_workspaceId, _userId, patch) { membership = patch; } },
|
|
142
|
+
workspacesRepository: { async findById(workspaceId) { return { id: workspaceId, slug: "acme", name: "Acme", ownerUserId: "1" }; } },
|
|
143
|
+
workspaceSettingsRepository: { async findInvitesRequireSameEmail() { return true; } },
|
|
144
|
+
invitationsAnyAccount: false,
|
|
145
|
+
async notifyInviter() {}
|
|
141
146
|
});
|
|
142
147
|
const user = { id: "11", email: invite.email };
|
|
143
148
|
const pending = output(workspacePendingInvitationsContract, "list", { pendingInvites: await service.listPendingInvitesForUser(user) });
|
|
@@ -146,7 +151,7 @@ test("pending and resolved invitation responses derive labels while acceptance s
|
|
|
146
151
|
assert.equal(resolved.roleLabel, "Operator");
|
|
147
152
|
assert.equal(resolved.roleSid, "safety_manager");
|
|
148
153
|
await service.acceptInviteByToken({ user, token });
|
|
149
|
-
assert.deepEqual(membership, { roleSid: "safety_manager", status: "active" });
|
|
154
|
+
assert.deepEqual(membership, { roleSid: "safety_manager", status: "active", acceptedInviteId: "10" });
|
|
150
155
|
assert.equal(Object.hasOwn(invite, "roleLabel"), false);
|
|
151
156
|
});
|
|
152
157
|
|
|
@@ -9,13 +9,8 @@ import { requireTestDatabase } from "@jskit-ai/database-runtime/server/testDatab
|
|
|
9
9
|
import { startTestFeatures } from "@jskit-ai/resource-runtime/test";
|
|
10
10
|
import { UsersExtensionsProvider } from "@jskit-ai/users-core/server/UsersExtensionsProvider";
|
|
11
11
|
import { UsersIdentityProvider } from "@jskit-ai/users-core/server/UsersIdentityProvider";
|
|
12
|
-
import
|
|
13
|
-
import usersUsername from "../../../users-core/migrations/users_core_profile_username.cjs";
|
|
14
|
-
import usersUpdatedAt from "../../../users-core/migrations/users_core_profile_updated_at.cjs";
|
|
12
|
+
import { WORKSPACES_TEST_MIGRATIONS } from "./workspacesMigrations.js";
|
|
15
13
|
import indexesByUser from "../../migrations/workspaces_core_indexes_by_user.cjs";
|
|
16
|
-
import workspacesInitial from "../../migrations/workspaces_core_initial.cjs";
|
|
17
|
-
import workspaceSettingsMigration from "../../migrations/workspaces_core_workspace_settings_single_name_source.cjs";
|
|
18
|
-
import workspaceColorMigration from "../../migrations/workspaces_core_workspaces_drop_color.cjs";
|
|
19
14
|
import { WorkspaceRecordsFeature } from "../../src/test/WorkspaceRecordsFeature.js";
|
|
20
15
|
|
|
21
16
|
// A person's workspaces are read through an index on every dialect: the statements workspaces.listForUserId (their
|
|
@@ -23,7 +18,6 @@ import { WorkspaceRecordsFeature } from "../../src/test/WorkspaceRecordsFeature.
|
|
|
23
18
|
// by the database's own planner. On SQLite and PostgreSQL the indexes are workspaces_core_indexes_by_user's; on
|
|
24
19
|
// MariaDB/MySQL they are the ones InnoDB made for the foreign keys, and the migration changes nothing.
|
|
25
20
|
|
|
26
|
-
const EARLIER_MIGRATIONS = [usersInitial, usersUsername, usersUpdatedAt, workspacesInitial, workspaceSettingsMigration, workspaceColorMigration];
|
|
27
21
|
const PEOPLE = 60;
|
|
28
22
|
// The index each read uses, by dialect: the migration's own, or InnoDB's for the foreign key.
|
|
29
23
|
const READS = Object.freeze({
|
|
@@ -152,7 +146,7 @@ function indexesByUserCases(open, { dialect, database = true, skip = false }) {
|
|
|
152
146
|
test(`a person's memberships and owned workspaces are read through an index (${dialect})`, { skip }, async (t) => {
|
|
153
147
|
if (database) requireTestDatabase(process.env);
|
|
154
148
|
const knex = await open(t);
|
|
155
|
-
for (const migration of
|
|
149
|
+
for (const migration of WORKSPACES_TEST_MIGRATIONS) await migration.up(knex);
|
|
156
150
|
await indexesByUser.up(knex);
|
|
157
151
|
const person = await seed(knex);
|
|
158
152
|
if (dialect === "postgres") await knex.raw("analyze");
|
|
@@ -67,6 +67,13 @@ export async function verifyInvitationTransactions(t, db) {
|
|
|
67
67
|
}
|
|
68
68
|
})]);
|
|
69
69
|
const { workspaces, memberships } = createWorkspaceRecords(resources);
|
|
70
|
+
// The pending invitations service's other collaborators, where only the invited address accepts (no anyAccount).
|
|
71
|
+
const INVITED_ADDRESS_ONLY = Object.freeze({
|
|
72
|
+
workspacesRepository: workspaces,
|
|
73
|
+
workspaceSettingsRepository: { async findInvitesRequireSameEmail() { return true; } },
|
|
74
|
+
invitationsAnyAccount: false,
|
|
75
|
+
async notifyInviter() {}
|
|
76
|
+
});
|
|
70
77
|
const invites = invitesRepository({ workspaceInvites: resources.workspaceInvites, workspaces });
|
|
71
78
|
const roleCatalog = createWorkspaceRoleCatalog({ roleCatalog: {
|
|
72
79
|
workspace: { defaultInviteRole: "member" },
|
|
@@ -109,7 +116,8 @@ export async function verifyInvitationTransactions(t, db) {
|
|
|
109
116
|
let participant = noInviteAcceptanceParticipant;
|
|
110
117
|
const pending = pendingService({
|
|
111
118
|
workspaceInvitesRepository: inviteRepository, workspaceMembershipsRepository: memberships, roleCatalog: createWorkspaceRoleCatalog(),
|
|
112
|
-
acceptanceParticipant: (...args) => participant(...args)
|
|
119
|
+
acceptanceParticipant: (...args) => participant(...args),
|
|
120
|
+
...INVITED_ADDRESS_ONLY
|
|
113
121
|
});
|
|
114
122
|
const options = { context: { actor: user, channel: "api", permissions: ["workspace.members.invite"] } };
|
|
115
123
|
const payload = { email: user.email, roleSid: "member" };
|
|
@@ -321,7 +329,8 @@ export async function verifyInvitationTransactions(t, db) {
|
|
|
321
329
|
let called = false;
|
|
322
330
|
const pending = pendingService({
|
|
323
331
|
workspaceInvitesRepository: invites, workspaceMembershipsRepository: memberships, roleCatalog: createWorkspaceRoleCatalog(),
|
|
324
|
-
acceptanceParticipant: async () => { called = true; }
|
|
332
|
+
acceptanceParticipant: async () => { called = true; },
|
|
333
|
+
...INVITED_ADDRESS_ONLY
|
|
325
334
|
});
|
|
326
335
|
const membershipBefore = await memberships.findByWorkspaceIdAndUserId(f.workspace.id, f.user.id);
|
|
327
336
|
await assert.rejects(pending.acceptInviteByToken({
|
|
@@ -330,7 +339,7 @@ export async function verifyInvitationTransactions(t, db) {
|
|
|
330
339
|
}), (error) => [401, 403, 404, 409].includes(error.status));
|
|
331
340
|
assert.equal(called, false);
|
|
332
341
|
assert.deepEqual(await memberships.findByWorkspaceIdAndUserId(f.workspace.id, f.user.id), membershipBefore);
|
|
333
|
-
if (state === "expired") assert.equal((await f.invitation(prepared)).status, "
|
|
342
|
+
if (state === "expired") assert.equal((await f.invitation(prepared)).status, "expired");
|
|
334
343
|
});
|
|
335
344
|
}
|
|
336
345
|
|
|
@@ -472,7 +481,8 @@ export async function verifyInvitationTransactions(t, db) {
|
|
|
472
481
|
if (acceptanceWins && competitor === "replace") assert.equal(loser.status, "fulfilled", loser.reason?.stack);
|
|
473
482
|
else {
|
|
474
483
|
assert.equal(loser.status, "rejected");
|
|
475
|
-
|
|
484
|
+
// A replaced invitation is stored expired, and redeeming it says so.
|
|
485
|
+
assert.equal(loser.reason.status, competitor === "replace" ? 409 : 404, loser.reason.stack);
|
|
476
486
|
}
|
|
477
487
|
assert.notEqual(connections[0], connections[1], "Competing units own independent database connections");
|
|
478
488
|
assert.equal(participation, acceptanceWins ? 1 : 0);
|