refactor: Remove reintroduced non-null assertions in Db calls (#3162)

* 🔥 Remove reintroduced non-null assertions

* 🔥 Remove duplicate cred references

* 🔥 Remove unneeded `@ts-ignore`

* 🔥 Remove another `@ts-ignore`

* 🔥 Remove outdated suite version

* 🔥 Remove leftover non-null assertion

Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>

* 🔥 Remove more leftovers

* 🔥 Remove unneeded optional chaining operators

Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
This commit is contained in:
Iván Ovejero
2022-04-28 18:39:57 +02:00
committed by GitHub
parent 2b008815ca
commit 5e2589e626
18 changed files with 132 additions and 299 deletions

View File

@@ -67,7 +67,7 @@ test(
expect(response.statusCode).toBe(200);
expect(response.body).toEqual({});
const user = await Db.collections.User!.findOneOrFail({ email: payload.email });
const user = await Db.collections.User.findOneOrFail({ email: payload.email });
expect(user.resetPasswordToken).toBeDefined();
expect(user.resetPasswordTokenExpiration).toBeGreaterThan(Math.ceil(Date.now() / 1000));
}),
@@ -85,7 +85,7 @@ test('POST /forgot-password should fail if emailing is not set up', async () =>
expect(response.statusCode).toBe(500);
const storedOwner = await Db.collections.User!.findOneOrFail({ email: owner.email });
const storedOwner = await Db.collections.User.findOneOrFail({ email: owner.email });
expect(storedOwner.resetPasswordToken).toBeNull();
});
@@ -109,7 +109,7 @@ test('POST /forgot-password should fail with invalid inputs', async () => {
const response = await authlessAgent.post('/forgot-password').send(invalidPayload);
expect(response.statusCode).toBe(400);
const storedOwner = await Db.collections.User!.findOneOrFail({ email: owner.email });
const storedOwner = await Db.collections.User.findOneOrFail({ email: owner.email });
expect(storedOwner.resetPasswordToken).toBeNull();
}),
);
@@ -133,7 +133,7 @@ test('GET /resolve-password-token should succeed with valid inputs', async () =>
const resetPasswordToken = uuid();
const resetPasswordTokenExpiration = Math.floor(Date.now() / 1000) + 100;
await Db.collections.User!.update(owner.id, {
await Db.collections.User.update(owner.id, {
resetPasswordToken,
resetPasswordTokenExpiration,
});
@@ -183,7 +183,7 @@ test('GET /resolve-password-token should fail if token is expired', async () =>
const resetPasswordToken = uuid();
const resetPasswordTokenExpiration = Math.floor(Date.now() / 1000) - 1;
await Db.collections.User!.update(owner.id, {
await Db.collections.User.update(owner.id, {
resetPasswordToken,
resetPasswordTokenExpiration,
});
@@ -205,7 +205,7 @@ test('POST /change-password should succeed with valid inputs', async () => {
const resetPasswordToken = uuid();
const resetPasswordTokenExpiration = Math.floor(Date.now() / 1000) + 100;
await Db.collections.User!.update(owner.id, {
await Db.collections.User.update(owner.id, {
resetPasswordToken,
resetPasswordTokenExpiration,
});
@@ -223,7 +223,7 @@ test('POST /change-password should succeed with valid inputs', async () => {
const authToken = utils.getAuthToken(response);
expect(authToken).toBeDefined();
const { password: storedPassword } = await Db.collections.User!.findOneOrFail(owner.id);
const { password: storedPassword } = await Db.collections.User.findOneOrFail(owner.id);
const comparisonResult = await compare(passwordToStore, storedPassword);
expect(comparisonResult).toBe(true);
@@ -238,7 +238,7 @@ test('POST /change-password should fail with invalid inputs', async () => {
const resetPasswordToken = uuid();
const resetPasswordTokenExpiration = Math.floor(Date.now() / 1000) + 100;
await Db.collections.User!.update(owner.id, {
await Db.collections.User.update(owner.id, {
resetPasswordToken,
resetPasswordTokenExpiration,
});
@@ -267,7 +267,7 @@ test('POST /change-password should fail with invalid inputs', async () => {
const response = await authlessAgent.post('/change-password').query(invalidPayload);
expect(response.statusCode).toBe(400);
const { password: storedPassword } = await Db.collections.User!.findOneOrFail();
const { password: storedPassword } = await Db.collections.User.findOneOrFail();
expect(owner.password).toBe(storedPassword);
}),
);
@@ -281,7 +281,7 @@ test('POST /change-password should fail when token has expired', async () => {
const resetPasswordToken = uuid();
const resetPasswordTokenExpiration = Math.floor(Date.now() / 1000) - 1;
await Db.collections.User!.update(owner.id, {
await Db.collections.User.update(owner.id, {
resetPasswordToken,
resetPasswordTokenExpiration,
});