@terreno/api 0.10.0 → 0.11.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.
@@ -121,4 +121,149 @@ describe("syncConsents", () => {
121
121
  expect(forms[0].slug).toBe("terms");
122
122
  expect(forms[1].slug).toBe("privacy");
123
123
  });
124
+
125
+ it("publishes new version when type changes", async () => {
126
+ await syncConsents({terms: baseDef});
127
+ const updated: ConsentFormDefinition = {...baseDef, type: "privacy"};
128
+ const result = await syncConsents({terms: updated});
129
+ expect(result.updated).toEqual(["terms"]);
130
+ });
131
+
132
+ it("publishes new version when order changes", async () => {
133
+ await syncConsents({terms: baseDef});
134
+ const updated = {...baseDef, order: 99};
135
+ const result = await syncConsents({terms: updated});
136
+ expect(result.updated).toEqual(["terms"]);
137
+ });
138
+
139
+ it("publishes new version when required changes", async () => {
140
+ await syncConsents({terms: baseDef});
141
+ const updated = {...baseDef, required: false};
142
+ const result = await syncConsents({terms: updated});
143
+ expect(result.updated).toEqual(["terms"]);
144
+ });
145
+
146
+ it("publishes new version when requireScrollToBottom changes", async () => {
147
+ await syncConsents({terms: baseDef});
148
+ const updated = {...baseDef, requireScrollToBottom: true};
149
+ const result = await syncConsents({terms: updated});
150
+ expect(result.updated).toEqual(["terms"]);
151
+ });
152
+
153
+ it("publishes new version when captureSignature changes", async () => {
154
+ await syncConsents({terms: baseDef});
155
+ const updated = {...baseDef, captureSignature: true};
156
+ const result = await syncConsents({terms: updated});
157
+ expect(result.updated).toEqual(["terms"]);
158
+ });
159
+
160
+ it("publishes new version when agreeButtonText changes", async () => {
161
+ await syncConsents({terms: baseDef});
162
+ const updated = {...baseDef, agreeButtonText: "Consent"};
163
+ const result = await syncConsents({terms: updated});
164
+ expect(result.updated).toEqual(["terms"]);
165
+ });
166
+
167
+ it("publishes new version when allowDecline changes", async () => {
168
+ await syncConsents({terms: baseDef});
169
+ const updated = {...baseDef, allowDecline: true};
170
+ const result = await syncConsents({terms: updated});
171
+ expect(result.updated).toEqual(["terms"]);
172
+ });
173
+
174
+ it("publishes new version when declineButtonText changes", async () => {
175
+ await syncConsents({terms: baseDef});
176
+ const updated = {...baseDef, allowDecline: true, declineButtonText: "No Thanks"};
177
+ const result = await syncConsents({terms: updated});
178
+ expect(result.updated).toEqual(["terms"]);
179
+ });
180
+
181
+ it("publishes new version when defaultLocale changes", async () => {
182
+ await syncConsents({terms: baseDef});
183
+ const updated = {...baseDef, defaultLocale: "es"};
184
+ const result = await syncConsents({terms: updated});
185
+ expect(result.updated).toEqual(["terms"]);
186
+ });
187
+
188
+ it("publishes new version when content locale count changes", async () => {
189
+ await syncConsents({terms: baseDef});
190
+ const updated = {...baseDef, content: {en: baseDef.content.en, es: "# Términos"}};
191
+ const result = await syncConsents({terms: updated});
192
+ expect(result.updated).toEqual(["terms"]);
193
+ });
194
+
195
+ it("publishes new version when checkbox count changes", async () => {
196
+ await syncConsents({
197
+ terms: {
198
+ ...baseDef,
199
+ checkboxes: [{label: "Agree", required: true}],
200
+ },
201
+ });
202
+ const updated = {
203
+ ...baseDef,
204
+ checkboxes: [
205
+ {label: "Agree", required: true},
206
+ {label: "Also agree", required: false},
207
+ ],
208
+ };
209
+ const result = await syncConsents({terms: updated});
210
+ expect(result.updated).toEqual(["terms"]);
211
+ });
212
+
213
+ it("publishes new version when checkbox label changes", async () => {
214
+ await syncConsents({
215
+ terms: {
216
+ ...baseDef,
217
+ checkboxes: [{label: "Agree", required: true}],
218
+ },
219
+ });
220
+ const updated = {
221
+ ...baseDef,
222
+ checkboxes: [{label: "I Agree", required: true}],
223
+ };
224
+ const result = await syncConsents({terms: updated});
225
+ expect(result.updated).toEqual(["terms"]);
226
+ });
227
+
228
+ it("publishes new version when checkbox confirmationPrompt changes", async () => {
229
+ await syncConsents({
230
+ terms: {
231
+ ...baseDef,
232
+ checkboxes: [{confirmationPrompt: "Sure?", label: "Agree", required: true}],
233
+ },
234
+ });
235
+ const updated = {
236
+ ...baseDef,
237
+ checkboxes: [{confirmationPrompt: "Are you sure?", label: "Agree", required: true}],
238
+ };
239
+ const result = await syncConsents({terms: updated});
240
+ expect(result.updated).toEqual(["terms"]);
241
+ });
242
+
243
+ it("leaves unchanged forms alone with checkboxes present", async () => {
244
+ const withCheckboxes = {
245
+ ...baseDef,
246
+ checkboxes: [{confirmationPrompt: "Sure?", label: "Agree", required: true}],
247
+ };
248
+ await syncConsents({terms: withCheckboxes});
249
+ const result = await syncConsents({terms: withCheckboxes});
250
+ expect(result.unchanged).toEqual(["terms"]);
251
+ });
252
+
253
+ it("dry run does not create new versions", async () => {
254
+ await syncConsents({terms: baseDef});
255
+ const updated = {...baseDef, title: "Updated"};
256
+ const result = await syncConsents({terms: updated}, {dryRun: true});
257
+ expect(result.updated).toEqual(["terms"]);
258
+ const forms = await ConsentForm.find({slug: "terms"});
259
+ expect(forms).toHaveLength(1); // No new version created
260
+ });
261
+
262
+ it("dry run does not deactivate forms", async () => {
263
+ await syncConsents({privacy: {...baseDef, title: "Privacy", type: "privacy"}, terms: baseDef});
264
+ const result = await syncConsents({terms: baseDef}, {deactivateRemoved: true, dryRun: true});
265
+ expect(result.deactivated).toEqual(["privacy"]);
266
+ const privacy = await ConsentForm.findOne({slug: "privacy"});
267
+ expect(privacy?.active).toBe(true); // Still active
268
+ });
124
269
  });
package/src/tests.ts CHANGED
@@ -162,7 +162,7 @@ const requiredSchema = new Schema<RequiredField>({
162
162
  });
163
163
  export const RequiredModel = model<RequiredField>("Required", requiredSchema);
164
164
 
165
- export function getBaseServer(): Express {
165
+ export const getBaseServer = (): Express => {
166
166
  const app = express();
167
167
  app.set("query parser", (str: string) => qs.parse(str, {arrayLimit: 200}));
168
168
 
@@ -186,12 +186,12 @@ export function getBaseServer(): Express {
186
186
  });
187
187
  app.use(express.json());
188
188
  return app;
189
- }
189
+ };
190
190
 
191
- export async function authAsUser(
191
+ export const authAsUser = async (
192
192
  app: express.Application,
193
193
  type: "admin" | "notAdmin"
194
- ): Promise<TestAgent> {
194
+ ): Promise<TestAgent> => {
195
195
  const email = type === "admin" ? "admin@example.com" : "notAdmin@example.com";
196
196
  const password = type === "admin" ? "securePassword" : "password";
197
197
 
@@ -199,9 +199,9 @@ export async function authAsUser(
199
199
  const res = await agent.post("/auth/login").send({email, password}).expect(200);
200
200
  await agent.set("authorization", `Bearer ${res.body.data.token}`);
201
201
  return agent;
202
- }
202
+ };
203
203
 
204
- export async function setupDb() {
204
+ export const setupDb = async () => {
205
205
  await mongoose
206
206
  .connect("mongodb://127.0.0.1/terreno?&connectTimeoutMS=360000")
207
207
  .catch(logger.catch);
@@ -233,7 +233,7 @@ export async function setupDb() {
233
233
 
234
234
  return [admin, notAdmin, adminOther];
235
235
  } catch (error) {
236
- console.error("Error setting up DB", error);
236
+ logger.error("Error setting up DB", error);
237
237
  throw error;
238
238
  }
239
- }
239
+ };
package/src/utils.ts CHANGED
@@ -4,14 +4,14 @@ import {logger} from "./logger";
4
4
 
5
5
  // A better version of mongoose's ObjectId.isValid,
6
6
  // which falsely will say any 12 character string is valid.
7
- export function isValidObjectId(id: string): boolean {
7
+ export const isValidObjectId = (id: string): boolean => {
8
8
  try {
9
9
  return new Types.ObjectId(id).toString() === id;
10
10
  } catch (error) {
11
11
  logger.error(`Error validating object id ${id}: ${error}`);
12
12
  return false;
13
13
  }
14
- }
14
+ };
15
15
 
16
16
  export const timeout = async (ms: number): Promise<NodeJS.Timeout> => {
17
17
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -25,7 +25,7 @@ export const timeout = async (ms: number): Promise<NodeJS.Timeout> => {
25
25
  * @param ignoredModels - Array of model names to skip validation for
26
26
  * @throws Error if any model is not set to strict mode or missing virtual settings
27
27
  */
28
- export function checkModelsStrict(ignoredModels: string[] = []): void {
28
+ export const checkModelsStrict = (ignoredModels: string[] = []): void => {
29
29
  const models = mongoose.modelNames();
30
30
  for (const model of models) {
31
31
  const schema = mongoose.model(model).schema;
@@ -44,4 +44,4 @@ export function checkModelsStrict(ignoredModels: string[] = []): void {
44
44
  throw new Error(`Model ${model} is not set to strict mode.`);
45
45
  }
46
46
  }
47
- }
47
+ };