Page MenuHomeSealhub

D200.id665.diff
No OneTemporary

D200.id665.diff

diff --git a/lib/app/base-chips/collections/password-reset-intents.subtest.js b/lib/app/base-chips/collections/password-reset-intents.subtest.js
--- a/lib/app/base-chips/collections/password-reset-intents.subtest.js
+++ b/lib/app/base-chips/collections/password-reset-intents.subtest.js
@@ -2,7 +2,7 @@
const axios = require("axios");
const assert = require("assert");
const { promise_timeout } = locreq("test_utils");
-const with_test_app = locreq("test_utils/with-test-app.js");
+const { with_running_app } = locreq("test_utils/with-test-app.js");
describe("password-reset-intents", () => {
async function create_a_user(app) {
@@ -19,7 +19,7 @@
}
it("tells you if the email address doesn't exist", async () =>
- with_test_app(async ({ app, base_url }) => {
+ with_running_app(async ({ app, base_url }) => {
try {
await axios.post(
`${base_url}/api/v1/collections/password-reset-intents`,
@@ -38,7 +38,7 @@
}));
it("allows anyone to create an intent, if the email exists", async () =>
- with_test_app(async ({ app, base_url }) => {
+ with_running_app(async ({ app, base_url }) => {
await create_a_user(app);
const data = (await axios.post(
`${base_url}/api/v1/collections/password-reset-intents`,
@@ -53,7 +53,7 @@
}));
it("tells you if the email address is malformed", async () =>
- with_test_app(async ({ base_url }) => {
+ with_running_app(async ({ base_url }) => {
try {
await axios.post(
`${base_url}/api/v1/collections/password-reset-intents`,
@@ -72,7 +72,7 @@
}));
it("sends an email with the reset password link", async () =>
- with_test_app(async ({ app, base_url, mail_api }) => {
+ with_running_app(async ({ app, base_url, mail_api }) => {
await create_a_user(app);
const data = (await axios.post(
`${base_url}/api/v1/collections/password-reset-intents`,
diff --git a/lib/app/base-chips/field-types/single_reference.subtest.js b/lib/app/base-chips/field-types/single_reference.subtest.js
--- a/lib/app/base-chips/field-types/single_reference.subtest.js
+++ b/lib/app/base-chips/field-types/single_reference.subtest.js
@@ -2,7 +2,7 @@
const locreq = require("locreq")(__dirname);
const axios = require("axios");
const { create_resource_as } = locreq("test_utils");
-const with_test_app = locreq("test_utils/with-test-app.js");
+const { with_running_app } = locreq("test_utils/with-test-app.js");
describe("single_reference", () => {
async function create_referencing_collections(app) {
@@ -28,7 +28,7 @@
}
it("should not allow a value that is not an existing id", async () =>
- with_test_app(async ({ app, base_url }) => {
+ with_running_app(async ({ app, base_url }) => {
await create_referencing_collections(app);
return axios
.post(`${base_url}/api/v1/collections/A`, {
@@ -46,7 +46,7 @@
}));
it("should allow a value that exists in B", async () =>
- with_test_app(async ({ app, base_url }) => {
+ with_running_app(async ({ app, base_url }) => {
create_referencing_collections(app);
const b_id = (await axios.post(`${base_url}/api/v1/collections/B`, {
number: 1,
@@ -57,7 +57,7 @@
}));
it("should not allow a value that exists in B but does not meet the filter criteria", async () =>
- with_test_app(async ({ app, base_url }) => {
+ with_running_app(async ({ app, base_url }) => {
create_referencing_collections(app);
const b_id = (await axios.post(`${base_url}/api/v1/collections/B`, {
number: 0,
@@ -79,7 +79,7 @@
}));
it("should allow a value that exists in B but does not meet the filter criteria", async () =>
- with_test_app(async ({ app, base_url }) => {
+ with_running_app(async ({ app, base_url }) => {
create_referencing_collections(app);
const b_id = (await axios.post(`${base_url}/api/v1/collections/B`, {
number: 1,
diff --git a/lib/app/base-chips/special_filters/IsReferencedByResourcesMatching.subtest.js b/lib/app/base-chips/special_filters/IsReferencedByResourcesMatching.subtest.js
--- a/lib/app/base-chips/special_filters/IsReferencedByResourcesMatching.subtest.js
+++ b/lib/app/base-chips/special_filters/IsReferencedByResourcesMatching.subtest.js
@@ -5,7 +5,7 @@
const { create_resource_as } = locreq("test_utils");
const IsReferencedByResourcesMatching = require("./IsReferencedByResourcesMatching");
-const with_test_app = locreq("test_utils/with-test-app.js");
+const { with_running_app } = locreq("test_utils/with-test-app.js");
describe("IsReferencedByResourcesMatching", () => {
async function setup(app) {
@@ -86,7 +86,7 @@
}
it("returns only users with role matching `allowed_values`", () =>
- with_test_app(async ({ app, base_url }) => {
+ with_running_app(async ({ app, base_url }) => {
await setup(app);
return axios
.get(`${base_url}/api/v1/collections/users/@staff`)
diff --git a/lib/app/base-chips/special_filters/matches.subtest.js b/lib/app/base-chips/special_filters/matches.subtest.js
--- a/lib/app/base-chips/special_filters/matches.subtest.js
+++ b/lib/app/base-chips/special_filters/matches.subtest.js
@@ -5,7 +5,7 @@
const { create_resource_as } = locreq("test_utils");
const matches = require("./matches");
-const with_test_app = locreq("test_utils/with-test-app.js");
+const { with_running_app } = locreq("test_utils/with-test-app.js");
describe("Matches", () => {
async function setup(app) {
@@ -35,7 +35,7 @@
}
it("returns only positive numbers when using @positive filter", () =>
- with_test_app(async ({ app, base_url }) => {
+ with_running_app(async ({ app, base_url }) => {
await setup(app);
return axios
.get(
@@ -50,7 +50,7 @@
}));
it("returns empty array when using both @positive and @negative filters", () =>
- with_test_app(async ({ app, base_url }) => {
+ with_running_app(async ({ app, base_url }) => {
await setup(app);
return axios
.get(`${base_url}/api/v1/collections/numbers/@positive/@negative`)
diff --git a/lib/email/smtp-mailer.js b/lib/email/smtp-mailer.js
--- a/lib/email/smtp-mailer.js
+++ b/lib/email/smtp-mailer.js
@@ -27,7 +27,7 @@
this.mail_config.from_address
}>`,
to,
- subject,
+ subject: subject.toString(),
text,
html,
attachments,
diff --git a/lib/email/templates/simple.test.js b/lib/email/templates/simple.test.js
--- a/lib/email/templates/simple.test.js
+++ b/lib/email/templates/simple.test.js
@@ -1,10 +1,10 @@
const locreq = require("locreq")(__dirname);
const assert = require("assert");
-const with_test_app = locreq("test_utils/with-test-app.js");
+const { with_running_app } = locreq("test_utils/with-test-app.js");
describe("simpleTemplate", () => {
it("sends an email", async () =>
- with_test_app(async ({ app, mail_api }) => {
+ with_running_app(async ({ app, mail_api }) => {
const message = await app.EmailTemplates.Simple(app, {
to: "test@example.com",
subject: "Congratulations!",
diff --git a/lib/http/routes/confirm-password-reset.test.js b/lib/http/routes/confirm-password-reset.test.js
--- a/lib/http/routes/confirm-password-reset.test.js
+++ b/lib/http/routes/confirm-password-reset.test.js
@@ -1,11 +1,11 @@
const locreq = require("locreq")(__dirname);
const axios = require("axios");
const assert = require("assert");
-const with_test_app = locreq("test_utils/with-test-app.js");
+const { with_running_app } = locreq("test_utils/with-test-app.js");
describe("confirm-password-reset", () => {
it("displays an html form", async () =>
- with_test_app(async ({ app, base_url }) => {
+ with_running_app(async ({ app, base_url }) => {
const response = await axios.get(
`${base_url}/confirm-password-reset?token=kupcia&email=dupcia`
);
diff --git a/lib/http/routes/finalize-password-reset.test.js b/lib/http/routes/finalize-password-reset.test.js
--- a/lib/http/routes/finalize-password-reset.test.js
+++ b/lib/http/routes/finalize-password-reset.test.js
@@ -3,7 +3,7 @@
const axios = require("axios");
const tough = require("tough-cookie");
const { promise_timeout, assert_throws_async } = locreq("test_utils");
-const with_test_app = locreq("test_utils/with-test-app.js");
+const { with_running_app } = locreq("test_utils/with-test-app.js");
describe("finalize password reset", () => {
async function create_a_user(app) {
@@ -20,7 +20,7 @@
}
it("allows to change a password (entire flow)", async () =>
- with_test_app(async ({ app, base_url, mail_api }) => {
+ with_running_app(async ({ app, base_url, mail_api }) => {
await create_a_user(app);
const cookieJar = new tough.CookieJar();
const options = {
diff --git a/lib/http/routes/finalize-registration-intent.test.js b/lib/http/routes/finalize-registration-intent.test.js
--- a/lib/http/routes/finalize-registration-intent.test.js
+++ b/lib/http/routes/finalize-registration-intent.test.js
@@ -3,11 +3,11 @@
const axios = require("axios");
const tough = require("tough-cookie");
const { promise_timeout, assert_throws_async } = locreq("test_utils");
-const with_test_app = locreq("test_utils/with-test-app.js");
+const { with_running_app } = locreq("test_utils/with-test-app.js");
describe("finalize registration", () => {
it("allows to register an account (entire flow)", async () =>
- with_test_app(async ({ app, base_url, mail_api }) => {
+ with_running_app(async ({ app, base_url, mail_api }) => {
const cookieJar = new tough.CookieJar();
const options = {
jar: cookieJar,
diff --git a/test_utils/with-test-app.js b/test_utils/with-test-app.js
--- a/test_utils/with-test-app.js
+++ b/test_utils/with-test-app.js
@@ -1,7 +1,12 @@
const locreq = require("locreq")(__dirname);
const axios = require("axios");
-module.exports = async function with_test_app(fn) {
+module.exports = {
+ with_stopped_app: with_test_app.bind(global, "auto_start" && false),
+ with_running_app: with_test_app.bind(global, "auto_start" && true),
+};
+
+async function with_test_app(auto_start, fn) {
let app = null;
const port = 8888;
const base_url = `http://localhost:${port}`;
@@ -41,15 +46,21 @@
}
);
- app.on("stop", async () =>
- Promise.all(
- app.ChipManager.get_all_collections().map(collection_name =>
- app.Datastore.remove(collection_name, {}, "just_one" && false)
- )
- )
- );
+ let clear_database_on_stop = true;
+
+ app.on("stop", async () => {
+ if (clear_database_on_stop) {
+ return Promise.all(
+ app.ChipManager.get_all_collections().map(collection_name =>
+ app.Datastore.remove(collection_name, {}, "just_one" && false)
+ )
+ );
+ }
+ });
- await app.start();
+ if (auto_start) {
+ await app.start();
+ }
try {
await axios.delete(`${smtp_api_url}/messages`);
@@ -64,11 +75,22 @@
get_message_by_id: async id =>
(await axios.get(`${smtp_api_url}/messages/${id}.html`)).data,
},
+ dont_clear_database_on_stop: () => (clear_database_on_stop = false),
+ rest_api: {
+ get: async url => (await axios.get(`${base_url}${url}`)).data,
+ delete: async url => (await axios.delete(`${base_url}${url}`)).data,
+ patch: async (url, data) =>
+ (await axios.patch(`${base_url}${url}`, data)).data,
+ },
});
- return await app.stop();
+ if (app.status !== "stopped") {
+ await app.stop();
+ }
} catch (e) {
- await app.stop();
+ if (app.status !== "stopped") {
+ await app.stop();
+ }
throw e;
}
-};
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 02:21 (17 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
548091
Default Alt Text
D200.id665.diff (11 KB)

Event Timeline