-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathcreate-organization.e2e.node.test.ts
More file actions
103 lines (90 loc) · 3.62 KB
/
Copy pathcreate-organization.e2e.node.test.ts
File metadata and controls
103 lines (90 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { assert, describe, it } from "@effect/vitest";
import { Effect, Exit } from "effect";
import {
CloudAuthApiTestContext,
CloudAuthApiTestContextLayer,
makeCloudAuthApiTestState,
} from "./cloud-auth-api.test-context";
import { makeWorkOSTestMembership, makeWorkOSTestState } from "./workos.test-layer";
import { makeAutumnTestState } from "../services/autumn.test-layer";
describe("create organization API", () => {
it.effect("lets a paid user create another organization through the HTTP API client", () => {
const state = makeCloudAuthApiTestState({
workos: makeWorkOSTestState({
memberships: [
makeWorkOSTestMembership("org_free_1", "active"),
makeWorkOSTestMembership("org_free_2", "active"),
makeWorkOSTestMembership("org_paid", "active"),
],
}),
autumn: makeAutumnTestState({
subscriptionsByOrgId: {
org_paid: [{ planId: "team", status: "active" }],
},
}),
});
return Effect.gen(function* () {
const { client } = yield* CloudAuthApiTestContext;
const result = yield* client.cloudAuth.createOrganization({
payload: { name: "Paid Extra Org" },
});
assert.deepEqual(result, { id: "org_created", name: "Paid Extra Org" });
assert.deepEqual(state.workos.createdOrganizations, [
{ id: "org_created", name: "Paid Extra Org" },
]);
assert.deepEqual(state.workos.createdMemberships, [
{ organizationId: "org_created", userId: "user_1", roleSlug: "admin" },
]);
assert.deepEqual(state.userStore.upsertedOrganizations, [
{ id: "org_created", name: "Paid Extra Org" },
]);
}).pipe(Effect.provide(CloudAuthApiTestContextLayer(state)));
});
it.effect(
"rejects a free-only user at the free organization limit through the HTTP API client",
() => {
const state = makeCloudAuthApiTestState({
workos: makeWorkOSTestState({
memberships: [
makeWorkOSTestMembership("org_free_1", "active"),
makeWorkOSTestMembership("org_free_2", "active"),
makeWorkOSTestMembership("org_free_3", "active"),
],
}),
});
return Effect.gen(function* () {
const { client } = yield* CloudAuthApiTestContext;
const exit = yield* Effect.exit(
client.cloudAuth.createOrganization({
payload: { name: "Blocked Org" },
}),
);
assert.isTrue(Exit.isFailure(exit));
assert.deepEqual(state.workos.createdOrganizations, []);
assert.deepEqual(state.workos.createdMemberships, []);
assert.deepEqual(state.userStore.upsertedOrganizations, []);
}).pipe(Effect.provide(CloudAuthApiTestContextLayer(state)));
},
);
it.effect("does not count pending memberships toward the free organization limit", () => {
const state = makeCloudAuthApiTestState({
workos: makeWorkOSTestState({
memberships: [
makeWorkOSTestMembership("org_free_1", "active"),
makeWorkOSTestMembership("org_free_2", "active"),
makeWorkOSTestMembership("org_invited", "pending"),
],
}),
});
return Effect.gen(function* () {
const { client } = yield* CloudAuthApiTestContext;
const result = yield* client.cloudAuth.createOrganization({
payload: { name: "Below Active Limit" },
});
assert.deepEqual(result, { id: "org_created", name: "Below Active Limit" });
assert.deepEqual(state.workos.createdOrganizations, [
{ id: "org_created", name: "Below Active Limit" },
]);
}).pipe(Effect.provide(CloudAuthApiTestContextLayer(state)));
});
});