Page MenuHomeSealhub

users.subtest.js
No OneTemporary

users.subtest.js

const locreq = require("locreq")(__dirname);
const assert = require("assert");
const { with_running_app } = locreq("test_utils/with-test-app.js");
const assert_throws_async = locreq("test_utils/assert_throws_async.js");
describe("users", () => {
describe("auto create admin", () => {
it("should automatically create a registration intent for the admin user", async () =>
with_running_app(async ({ app, mail_api }) => {
const { items: registration_intents } = await app.run_action(
new app.Sealious.SuperContext(),
["collections", "registration-intents"],
"show",
{ filter: { email: app.manifest.admin_email } }
);
assert.equal(registration_intents.length, 1);
assert.equal(registration_intents[0].body.role, "admin");
}));
});
describe("users routes", () => {
it("should correctly handle me when not logged in", async () =>
with_running_app(async ({ app, rest_api }) => {
await assert_throws_async(
async () =>
await rest_api.get(
"/api/v1/users/me?format%5Broles%5D=expand"
),
e => {
assert.equal(e.response.status, 401);
assert.equal(
e.response.data.message,
"You're not logged in!"
);
}
);
}));
});
describe("login", () => {
it("correctly rejects when provided incorrect password", async () =>
with_running_app(async ({ app, rest_api }) => {
await add_user(app);
const incorrect_password_variants = [
{ password: "", message: "Missing password!" },
{
password: "incorrect_password",
message: "Incorrect password!",
},
];
for (let variant of incorrect_password_variants) {
await assert_throws_async(
async () =>
await rest_api.login({
username: "seal",
password: variant.password,
}),
e => {
assert.equal(e.response.status, 401);
assert.equal(
e.response.data.message,
variant.message
);
}
);
}
}));
async function add_user(app) {
return app.run_action(
new app.Sealious.SuperContext(),
["collections", "users"],
"create",
{
username: "seal",
password: "seal",
email: "seal@sealious.com",
}
);
}
it("correctly rejects when provided incorrect username", async () =>
with_running_app(async ({ app, rest_api }) => {
await add_user(app);
const incorrect_username_variants = [
{ username: "", message: "Missing username!" },
{
username: "incorrect_username",
message: "Incorrect username!",
},
];
for (let variant of incorrect_username_variants) {
await assert_throws_async(
async () =>
await rest_api.login({
username: variant.username,
password: "seal",
}),
e => {
assert.equal(e.response.status, 401);
assert.equal(
e.response.data.message,
variant.message
);
}
);
}
}));
});
});

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 24, 14:02 (18 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557249
Default Alt Text
users.subtest.js (2 KB)

Event Timeline