@saasicat/persistence-testing 0.26.1 → 0.27.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/LICENSE +90 -201
- package/dist/index.cjs +109 -0
- package/dist/index.d.cts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +109 -0
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,202 +1,91 @@
|
|
|
1
|
+
Required Notice: Copyright Taci Ülker (https://github.com/uelker70/saasicat)
|
|
1
2
|
|
|
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
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
-
modifications, and in Source or Object form, provided that You
|
|
93
|
-
meet the following conditions:
|
|
94
|
-
|
|
95
|
-
(a) You must give any other recipients of the Work or
|
|
96
|
-
Derivative Works a copy of this License; and
|
|
97
|
-
|
|
98
|
-
(b) You must cause any modified files to carry prominent notices
|
|
99
|
-
stating that You changed the files; and
|
|
100
|
-
|
|
101
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
-
that You distribute, all copyright, patent, trademark, and
|
|
103
|
-
attribution notices from the Source form of the Work,
|
|
104
|
-
excluding those notices that do not pertain to any part of
|
|
105
|
-
the Derivative Works; and
|
|
106
|
-
|
|
107
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
-
distribution, then any Derivative Works that You distribute must
|
|
109
|
-
include a readable copy of the attribution notices contained
|
|
110
|
-
within such NOTICE file, excluding those notices that do not
|
|
111
|
-
pertain to any part of the Derivative Works, in at least one
|
|
112
|
-
of the following places: within a NOTICE text file distributed
|
|
113
|
-
as part of the Derivative Works; within the Source form or
|
|
114
|
-
documentation, if provided along with the Derivative Works; or,
|
|
115
|
-
within a display generated by the Derivative Works, if and
|
|
116
|
-
wherever such third-party notices normally appear. The contents
|
|
117
|
-
of the NOTICE file are for informational purposes only and
|
|
118
|
-
do not modify the License. You may add Your own attribution
|
|
119
|
-
notices within Derivative Works that You distribute, alongside
|
|
120
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
-
that such additional attribution notices cannot be construed
|
|
122
|
-
as modifying the License.
|
|
123
|
-
|
|
124
|
-
You may add Your own copyright statement to Your modifications and
|
|
125
|
-
may provide additional or different license terms and conditions
|
|
126
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
-
the conditions stated in this License.
|
|
130
|
-
|
|
131
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
-
this License, without any additional terms or conditions.
|
|
135
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
-
the terms of any separate license agreement you may have executed
|
|
137
|
-
with Licensor regarding such Contributions.
|
|
138
|
-
|
|
139
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
-
except as required for reasonable and customary use in describing the
|
|
142
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
-
|
|
144
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
-
implied, including, without limitation, any warranties or conditions
|
|
149
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
-
appropriateness of using or redistributing the Work and assume any
|
|
152
|
-
risks associated with Your exercise of permissions under this License.
|
|
153
|
-
|
|
154
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
-
unless required by applicable law (such as deliberate and grossly
|
|
157
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
-
liable to You for damages, including any direct, indirect, special,
|
|
159
|
-
incidental, or consequential damages of any character arising as a
|
|
160
|
-
result of this License or out of the use or inability to use the
|
|
161
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
-
other commercial damages or losses), even if such Contributor
|
|
164
|
-
has been advised of the possibility of such damages.
|
|
165
|
-
|
|
166
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
-
or other liability obligations and/or rights consistent with this
|
|
170
|
-
License. However, in accepting such obligations, You may act only
|
|
171
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
-
defend, and hold each Contributor harmless for any liability
|
|
174
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
-
of your accepting any such warranty or additional liability.
|
|
176
|
-
|
|
177
|
-
END OF TERMS AND CONDITIONS
|
|
178
|
-
|
|
179
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
-
|
|
181
|
-
To apply the Apache License to your work, attach the following
|
|
182
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
-
replaced with your own identifying information. (Don't include
|
|
184
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
-
comment syntax for the file format. We also recommend that a
|
|
186
|
-
file or class name and description of purpose be included on the
|
|
187
|
-
same "printed page" as the copyright notice for easier
|
|
188
|
-
identification within third-party archives.
|
|
189
|
-
|
|
190
|
-
Copyright [yyyy] [name of copyright owner]
|
|
191
|
-
|
|
192
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
-
you may not use this file except in compliance with the License.
|
|
194
|
-
You may obtain a copy of the License at
|
|
195
|
-
|
|
196
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
-
|
|
198
|
-
Unless required by applicable law or agreed to in writing, software
|
|
199
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
-
See the License for the specific language governing permissions and
|
|
202
|
-
limitations under the License.
|
|
3
|
+
# PolyForm Shield License 1.0.0
|
|
4
|
+
|
|
5
|
+
<https://polyformproject.org/licenses/shield/1.0.0>
|
|
6
|
+
|
|
7
|
+
## Acceptance
|
|
8
|
+
|
|
9
|
+
In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
|
|
14
|
+
|
|
15
|
+
## Distribution License
|
|
16
|
+
|
|
17
|
+
The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
|
|
18
|
+
|
|
19
|
+
## Notices
|
|
20
|
+
|
|
21
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
|
|
22
|
+
|
|
23
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
24
|
+
|
|
25
|
+
## Changes and New Works License
|
|
26
|
+
|
|
27
|
+
The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
|
|
28
|
+
|
|
29
|
+
## Patent License
|
|
30
|
+
|
|
31
|
+
The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
|
|
32
|
+
|
|
33
|
+
## Noncompete
|
|
34
|
+
|
|
35
|
+
Any purpose is a permitted purpose, except for providing any product that competes with the software or any product the licensor or any of its affiliates provides using the software.
|
|
36
|
+
|
|
37
|
+
## Competition
|
|
38
|
+
|
|
39
|
+
Goods and services compete even when they provide functionality through different kinds of interfaces or for different technical platforms. Applications can compete with services, libraries with plugins, frameworks with development tools, and so on, even if they're written in different programming languages or for different computer architectures. Goods and services compete even when provided free of charge. If you market a product as a practical substitute for the software or another product, it definitely competes.
|
|
40
|
+
|
|
41
|
+
## New Products
|
|
42
|
+
|
|
43
|
+
If you are using the software to provide a product that does not compete, but the licensor or any of its affiliates brings your product into competition by providing a new version of the software or another product using the software, you may continue using versions of the software available under these terms beforehand to provide your competing product, but not any later versions.
|
|
44
|
+
|
|
45
|
+
## Discontinued Products
|
|
46
|
+
|
|
47
|
+
You may begin using the software to compete with a product or service that the licensor or any of its affiliates has stopped providing, unless the licensor includes a plain-text line beginning with `Licensor Line of Business:` with the software that mentions that line of business. For example:
|
|
48
|
+
|
|
49
|
+
> Licensor Line of Business: YoyodyneCMS Content Management System (http://example.com/cms)
|
|
50
|
+
|
|
51
|
+
## Sales of Business
|
|
52
|
+
|
|
53
|
+
If the licensor or any of its affiliates sells a line of business developing the software or using the software to provide a product, the buyer can also enforce [Noncompete](#noncompete) for that product.
|
|
54
|
+
|
|
55
|
+
## Fair Use
|
|
56
|
+
|
|
57
|
+
You may have "fair use" rights for the software under the law. These terms do not limit them.
|
|
58
|
+
|
|
59
|
+
## No Other Rights
|
|
60
|
+
|
|
61
|
+
These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
|
|
62
|
+
|
|
63
|
+
## Patent Defense
|
|
64
|
+
|
|
65
|
+
If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
66
|
+
|
|
67
|
+
## Violations
|
|
68
|
+
|
|
69
|
+
The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
|
|
70
|
+
|
|
71
|
+
## No Liability
|
|
72
|
+
|
|
73
|
+
***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
|
|
74
|
+
|
|
75
|
+
## Definitions
|
|
76
|
+
|
|
77
|
+
The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
|
|
78
|
+
|
|
79
|
+
A **product** can be a good or service, or a combination of them.
|
|
80
|
+
|
|
81
|
+
**You** refers to the individual or entity agreeing to these terms.
|
|
82
|
+
|
|
83
|
+
**Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all its affiliates.
|
|
84
|
+
|
|
85
|
+
**Affiliates** means the other organizations than an organization has control over, is under the control of, or is under common control with.
|
|
86
|
+
|
|
87
|
+
**Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
88
|
+
|
|
89
|
+
**Your licenses** are all the licenses granted to you for the software under these terms.
|
|
90
|
+
|
|
91
|
+
**Use** means anything you do with the software requiring one of your licenses.
|
package/dist/index.cjs
CHANGED
|
@@ -631,6 +631,115 @@ function persistenceAdapterContract(options) {
|
|
|
631
631
|
import_strict.default.equal(await adapter.mfa.getSecret("admin-1"), null);
|
|
632
632
|
import_strict.default.equal(await adapter.mfa.isEnabled("admin-1"), false);
|
|
633
633
|
});
|
|
634
|
+
(0, import_node_test.test)("finds the subscription the id names, not merely a subscription", async (t) => {
|
|
635
|
+
const { adapter, seed } = harness;
|
|
636
|
+
if (!adapter.promoSubscriptionLookup) {
|
|
637
|
+
t.skip("adapter provides no PromoSubscriptionLookup");
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
const { planVersionId } = await seed.createPlanVersion({
|
|
641
|
+
planKey: "STARTER",
|
|
642
|
+
version: 1,
|
|
643
|
+
quotas: { users: 5 },
|
|
644
|
+
features: ["CORE"],
|
|
645
|
+
published: true
|
|
646
|
+
});
|
|
647
|
+
const first = await seed.createSubscription({
|
|
648
|
+
tenantId: "tenant-a",
|
|
649
|
+
plan: "STARTER",
|
|
650
|
+
planVersionId
|
|
651
|
+
});
|
|
652
|
+
const second = await seed.createSubscription({
|
|
653
|
+
tenantId: "tenant-b",
|
|
654
|
+
plan: "STARTER",
|
|
655
|
+
planVersionId
|
|
656
|
+
});
|
|
657
|
+
const found = await adapter.promoSubscriptionLookup.findById(second.subscriptionId);
|
|
658
|
+
import_strict.default.ok(found, "the lookup found nothing for an id that exists");
|
|
659
|
+
import_strict.default.equal(found.id, second.subscriptionId);
|
|
660
|
+
import_strict.default.equal(found.tenantId, "tenant-b", "it returned another tenant\u2019s subscription");
|
|
661
|
+
import_strict.default.notEqual(found.id, first.subscriptionId);
|
|
662
|
+
});
|
|
663
|
+
(0, import_node_test.test)("returns null for an id that does not exist", async (t) => {
|
|
664
|
+
const { adapter, seed } = harness;
|
|
665
|
+
if (!adapter.promoSubscriptionLookup) {
|
|
666
|
+
t.skip("adapter provides no PromoSubscriptionLookup");
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
const { planVersionId } = await seed.createPlanVersion({
|
|
670
|
+
planKey: "STARTER",
|
|
671
|
+
version: 1,
|
|
672
|
+
quotas: {},
|
|
673
|
+
features: [],
|
|
674
|
+
published: true
|
|
675
|
+
});
|
|
676
|
+
await seed.createSubscription({ tenantId: "tenant-a", plan: "STARTER", planVersionId });
|
|
677
|
+
import_strict.default.equal(
|
|
678
|
+
await adapter.promoSubscriptionLookup.findById(
|
|
679
|
+
"00000000-0000-4000-8000-000000000000"
|
|
680
|
+
),
|
|
681
|
+
null
|
|
682
|
+
);
|
|
683
|
+
});
|
|
684
|
+
(0, import_node_test.test)("carries the fields a promo rule reads: cycle and start date", async (t) => {
|
|
685
|
+
const { adapter, seed } = harness;
|
|
686
|
+
if (!adapter.promoSubscriptionLookup) {
|
|
687
|
+
t.skip("adapter provides no PromoSubscriptionLookup");
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
const { planVersionId } = await seed.createPlanVersion({
|
|
691
|
+
planKey: "PRO",
|
|
692
|
+
version: 1,
|
|
693
|
+
quotas: {},
|
|
694
|
+
features: [],
|
|
695
|
+
published: true
|
|
696
|
+
});
|
|
697
|
+
const startedAt = /* @__PURE__ */ new Date("2026-03-04T05:06:07.000Z");
|
|
698
|
+
const dated = await seed.createSubscription({
|
|
699
|
+
tenantId: "tenant-a",
|
|
700
|
+
plan: "PRO",
|
|
701
|
+
planVersionId,
|
|
702
|
+
billingCycle: "MONTHLY",
|
|
703
|
+
startedAt
|
|
704
|
+
});
|
|
705
|
+
const undated = await seed.createSubscription({
|
|
706
|
+
tenantId: "tenant-b",
|
|
707
|
+
plan: "PRO",
|
|
708
|
+
planVersionId
|
|
709
|
+
});
|
|
710
|
+
const withDate = await adapter.promoSubscriptionLookup.findById(dated.subscriptionId);
|
|
711
|
+
import_strict.default.equal(withDate?.plan, "PRO");
|
|
712
|
+
import_strict.default.equal(withDate?.billingCycle, "MONTHLY");
|
|
713
|
+
import_strict.default.equal(withDate?.startedAt?.toISOString(), startedAt.toISOString());
|
|
714
|
+
const withoutDate = await adapter.promoSubscriptionLookup.findById(
|
|
715
|
+
undated.subscriptionId
|
|
716
|
+
);
|
|
717
|
+
import_strict.default.equal(withoutDate?.startedAt, null, "an unset start date came back as a date");
|
|
718
|
+
});
|
|
719
|
+
(0, import_node_test.test)("reads inside a transaction, so validation and redemption agree", async (t) => {
|
|
720
|
+
const { adapter, seed } = harness;
|
|
721
|
+
if (!adapter.promoSubscriptionLookup) {
|
|
722
|
+
t.skip("adapter provides no PromoSubscriptionLookup");
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
const { planVersionId } = await seed.createPlanVersion({
|
|
726
|
+
planKey: "STARTER",
|
|
727
|
+
version: 1,
|
|
728
|
+
quotas: {},
|
|
729
|
+
features: [],
|
|
730
|
+
published: true
|
|
731
|
+
});
|
|
732
|
+
const { subscriptionId } = await seed.createSubscription({
|
|
733
|
+
tenantId: "tenant-a",
|
|
734
|
+
plan: "STARTER",
|
|
735
|
+
planVersionId
|
|
736
|
+
});
|
|
737
|
+
const seen = await adapter.transactionRunner.run(
|
|
738
|
+
async (tx) => adapter.promoSubscriptionLookup.findById(subscriptionId, tx)
|
|
739
|
+
);
|
|
740
|
+
import_strict.default.equal(seen?.id, subscriptionId);
|
|
741
|
+
import_strict.default.equal(seen?.tenantId, "tenant-a");
|
|
742
|
+
});
|
|
634
743
|
(0, import_node_test.test)("immutable subscription contracts (append-only, terminate-only)", (t) => {
|
|
635
744
|
if (!harness.adapter.subscriptionContractRepository) {
|
|
636
745
|
t.skip("adapter provides no SubscriptionContractRepository \u2014 scenario pending");
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PersistenceCapabilities, TransactionRunner, SubscriptionRepository, PlanVersionRepository, PromoCodeRepository, PromoCodeRedemptionRepository, MfaPort, AuditPort, AuditQueryPort, SubscriptionContractRepository, TenantSubscriptionWritePort, BundleRepository, PlanRepository } from '@saasicat/types';
|
|
1
|
+
import { PersistenceCapabilities, TransactionRunner, SubscriptionRepository, PlanVersionRepository, PromoCodeRepository, PromoCodeRedemptionRepository, MfaPort, AuditPort, AuditQueryPort, SubscriptionContractRepository, TenantSubscriptionWritePort, BundleRepository, PlanRepository, PromoSubscriptionLookup } from '@saasicat/types';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Port instances under test. Required members define the minimum an adapter
|
|
@@ -27,6 +27,16 @@ interface ContractAdapterInstances {
|
|
|
27
27
|
bundleRepository?: BundleRepository;
|
|
28
28
|
/** Enables PlanVersion lifecycle, identity and validity-window scenarios. */
|
|
29
29
|
planRepository?: PlanRepository;
|
|
30
|
+
/**
|
|
31
|
+
* Enables the promo subscription lookup scenarios.
|
|
32
|
+
*
|
|
33
|
+
* Worth its own entry rather than being folded into
|
|
34
|
+
* `subscriptionRepository`: this is the read a promo code is validated
|
|
35
|
+
* against, so a wrong row here decides that a discount applies to a
|
|
36
|
+
* subscription it was not meant for. It answers by subscription id, not by
|
|
37
|
+
* tenant, which is what makes selecting the wrong row possible at all.
|
|
38
|
+
*/
|
|
39
|
+
promoSubscriptionLookup?: PromoSubscriptionLookup;
|
|
30
40
|
}
|
|
31
41
|
/** Fixture writers — implemented per adapter against its own schema. */
|
|
32
42
|
interface ContractSeed {
|
|
@@ -46,6 +56,10 @@ interface ContractSeed {
|
|
|
46
56
|
planVersionId: string;
|
|
47
57
|
pendingPlanVersionId?: string;
|
|
48
58
|
status?: string;
|
|
59
|
+
/** Defaults to the column default; set it where a scenario reads it. */
|
|
60
|
+
billingCycle?: string;
|
|
61
|
+
/** Defaults to null; set it where a scenario reads it. */
|
|
62
|
+
startedAt?: Date;
|
|
49
63
|
}): Promise<{
|
|
50
64
|
subscriptionId: string;
|
|
51
65
|
}>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PersistenceCapabilities, TransactionRunner, SubscriptionRepository, PlanVersionRepository, PromoCodeRepository, PromoCodeRedemptionRepository, MfaPort, AuditPort, AuditQueryPort, SubscriptionContractRepository, TenantSubscriptionWritePort, BundleRepository, PlanRepository } from '@saasicat/types';
|
|
1
|
+
import { PersistenceCapabilities, TransactionRunner, SubscriptionRepository, PlanVersionRepository, PromoCodeRepository, PromoCodeRedemptionRepository, MfaPort, AuditPort, AuditQueryPort, SubscriptionContractRepository, TenantSubscriptionWritePort, BundleRepository, PlanRepository, PromoSubscriptionLookup } from '@saasicat/types';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Port instances under test. Required members define the minimum an adapter
|
|
@@ -27,6 +27,16 @@ interface ContractAdapterInstances {
|
|
|
27
27
|
bundleRepository?: BundleRepository;
|
|
28
28
|
/** Enables PlanVersion lifecycle, identity and validity-window scenarios. */
|
|
29
29
|
planRepository?: PlanRepository;
|
|
30
|
+
/**
|
|
31
|
+
* Enables the promo subscription lookup scenarios.
|
|
32
|
+
*
|
|
33
|
+
* Worth its own entry rather than being folded into
|
|
34
|
+
* `subscriptionRepository`: this is the read a promo code is validated
|
|
35
|
+
* against, so a wrong row here decides that a discount applies to a
|
|
36
|
+
* subscription it was not meant for. It answers by subscription id, not by
|
|
37
|
+
* tenant, which is what makes selecting the wrong row possible at all.
|
|
38
|
+
*/
|
|
39
|
+
promoSubscriptionLookup?: PromoSubscriptionLookup;
|
|
30
40
|
}
|
|
31
41
|
/** Fixture writers — implemented per adapter against its own schema. */
|
|
32
42
|
interface ContractSeed {
|
|
@@ -46,6 +56,10 @@ interface ContractSeed {
|
|
|
46
56
|
planVersionId: string;
|
|
47
57
|
pendingPlanVersionId?: string;
|
|
48
58
|
status?: string;
|
|
59
|
+
/** Defaults to the column default; set it where a scenario reads it. */
|
|
60
|
+
billingCycle?: string;
|
|
61
|
+
/** Defaults to null; set it where a scenario reads it. */
|
|
62
|
+
startedAt?: Date;
|
|
49
63
|
}): Promise<{
|
|
50
64
|
subscriptionId: string;
|
|
51
65
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -595,6 +595,115 @@ function persistenceAdapterContract(options) {
|
|
|
595
595
|
assert.equal(await adapter.mfa.getSecret("admin-1"), null);
|
|
596
596
|
assert.equal(await adapter.mfa.isEnabled("admin-1"), false);
|
|
597
597
|
});
|
|
598
|
+
test("finds the subscription the id names, not merely a subscription", async (t) => {
|
|
599
|
+
const { adapter, seed } = harness;
|
|
600
|
+
if (!adapter.promoSubscriptionLookup) {
|
|
601
|
+
t.skip("adapter provides no PromoSubscriptionLookup");
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
const { planVersionId } = await seed.createPlanVersion({
|
|
605
|
+
planKey: "STARTER",
|
|
606
|
+
version: 1,
|
|
607
|
+
quotas: { users: 5 },
|
|
608
|
+
features: ["CORE"],
|
|
609
|
+
published: true
|
|
610
|
+
});
|
|
611
|
+
const first = await seed.createSubscription({
|
|
612
|
+
tenantId: "tenant-a",
|
|
613
|
+
plan: "STARTER",
|
|
614
|
+
planVersionId
|
|
615
|
+
});
|
|
616
|
+
const second = await seed.createSubscription({
|
|
617
|
+
tenantId: "tenant-b",
|
|
618
|
+
plan: "STARTER",
|
|
619
|
+
planVersionId
|
|
620
|
+
});
|
|
621
|
+
const found = await adapter.promoSubscriptionLookup.findById(second.subscriptionId);
|
|
622
|
+
assert.ok(found, "the lookup found nothing for an id that exists");
|
|
623
|
+
assert.equal(found.id, second.subscriptionId);
|
|
624
|
+
assert.equal(found.tenantId, "tenant-b", "it returned another tenant\u2019s subscription");
|
|
625
|
+
assert.notEqual(found.id, first.subscriptionId);
|
|
626
|
+
});
|
|
627
|
+
test("returns null for an id that does not exist", async (t) => {
|
|
628
|
+
const { adapter, seed } = harness;
|
|
629
|
+
if (!adapter.promoSubscriptionLookup) {
|
|
630
|
+
t.skip("adapter provides no PromoSubscriptionLookup");
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
const { planVersionId } = await seed.createPlanVersion({
|
|
634
|
+
planKey: "STARTER",
|
|
635
|
+
version: 1,
|
|
636
|
+
quotas: {},
|
|
637
|
+
features: [],
|
|
638
|
+
published: true
|
|
639
|
+
});
|
|
640
|
+
await seed.createSubscription({ tenantId: "tenant-a", plan: "STARTER", planVersionId });
|
|
641
|
+
assert.equal(
|
|
642
|
+
await adapter.promoSubscriptionLookup.findById(
|
|
643
|
+
"00000000-0000-4000-8000-000000000000"
|
|
644
|
+
),
|
|
645
|
+
null
|
|
646
|
+
);
|
|
647
|
+
});
|
|
648
|
+
test("carries the fields a promo rule reads: cycle and start date", async (t) => {
|
|
649
|
+
const { adapter, seed } = harness;
|
|
650
|
+
if (!adapter.promoSubscriptionLookup) {
|
|
651
|
+
t.skip("adapter provides no PromoSubscriptionLookup");
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
const { planVersionId } = await seed.createPlanVersion({
|
|
655
|
+
planKey: "PRO",
|
|
656
|
+
version: 1,
|
|
657
|
+
quotas: {},
|
|
658
|
+
features: [],
|
|
659
|
+
published: true
|
|
660
|
+
});
|
|
661
|
+
const startedAt = /* @__PURE__ */ new Date("2026-03-04T05:06:07.000Z");
|
|
662
|
+
const dated = await seed.createSubscription({
|
|
663
|
+
tenantId: "tenant-a",
|
|
664
|
+
plan: "PRO",
|
|
665
|
+
planVersionId,
|
|
666
|
+
billingCycle: "MONTHLY",
|
|
667
|
+
startedAt
|
|
668
|
+
});
|
|
669
|
+
const undated = await seed.createSubscription({
|
|
670
|
+
tenantId: "tenant-b",
|
|
671
|
+
plan: "PRO",
|
|
672
|
+
planVersionId
|
|
673
|
+
});
|
|
674
|
+
const withDate = await adapter.promoSubscriptionLookup.findById(dated.subscriptionId);
|
|
675
|
+
assert.equal(withDate?.plan, "PRO");
|
|
676
|
+
assert.equal(withDate?.billingCycle, "MONTHLY");
|
|
677
|
+
assert.equal(withDate?.startedAt?.toISOString(), startedAt.toISOString());
|
|
678
|
+
const withoutDate = await adapter.promoSubscriptionLookup.findById(
|
|
679
|
+
undated.subscriptionId
|
|
680
|
+
);
|
|
681
|
+
assert.equal(withoutDate?.startedAt, null, "an unset start date came back as a date");
|
|
682
|
+
});
|
|
683
|
+
test("reads inside a transaction, so validation and redemption agree", async (t) => {
|
|
684
|
+
const { adapter, seed } = harness;
|
|
685
|
+
if (!adapter.promoSubscriptionLookup) {
|
|
686
|
+
t.skip("adapter provides no PromoSubscriptionLookup");
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
const { planVersionId } = await seed.createPlanVersion({
|
|
690
|
+
planKey: "STARTER",
|
|
691
|
+
version: 1,
|
|
692
|
+
quotas: {},
|
|
693
|
+
features: [],
|
|
694
|
+
published: true
|
|
695
|
+
});
|
|
696
|
+
const { subscriptionId } = await seed.createSubscription({
|
|
697
|
+
tenantId: "tenant-a",
|
|
698
|
+
plan: "STARTER",
|
|
699
|
+
planVersionId
|
|
700
|
+
});
|
|
701
|
+
const seen = await adapter.transactionRunner.run(
|
|
702
|
+
async (tx) => adapter.promoSubscriptionLookup.findById(subscriptionId, tx)
|
|
703
|
+
);
|
|
704
|
+
assert.equal(seen?.id, subscriptionId);
|
|
705
|
+
assert.equal(seen?.tenantId, "tenant-a");
|
|
706
|
+
});
|
|
598
707
|
test("immutable subscription contracts (append-only, terminate-only)", (t) => {
|
|
599
708
|
if (!harness.adapter.subscriptionContractRepository) {
|
|
600
709
|
t.skip("adapter provides no SubscriptionContractRepository \u2014 scenario pending");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saasicat/persistence-testing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Contract test kit for SaaSicat persistence adapters: one node:test suite that every adapter (Prisma, Drizzle, ...) must pass against a real database — locks, transaction rollback, atomic promo claims, tenant isolation, audit/MFA roundtrips.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@saasicat/types": "^0.
|
|
25
|
+
"@saasicat/types": "^0.27.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^25.6.0",
|
|
29
29
|
"tsup": "^8.0.0",
|
|
30
30
|
"typescript": "^6.0.0"
|
|
31
31
|
},
|
|
32
|
-
"license": "
|
|
32
|
+
"license": "PolyForm-Shield-1.0.0",
|
|
33
33
|
"author": "Taci Uelker",
|
|
34
34
|
"homepage": "https://github.com/uelker70/saasicat",
|
|
35
35
|
"repository": {
|