remove useless tests

This commit is contained in:
m5r 2021-08-20 08:56:07 +08:00
parent 30eebe246e
commit daf599022f
4 changed files with 1 additions and 174 deletions

View File

@ -1,4 +1,4 @@
name: Deploy to Railway name: Deployment pipeline
on: [push, pull_request] on: [push, pull_request]

View File

@ -1,59 +0,0 @@
import { hash256, Ctx } from "blitz";
import previewEmail from "preview-email";
import forgotPassword from "./forgot-password";
import db from "../../../db";
beforeEach(async () => {
await db.$reset();
});
const generatedToken = "plain-token";
jest.mock("blitz", () => ({
...jest.requireActual<object>("blitz")!,
generateToken: () => generatedToken,
}));
jest.mock("preview-email", () => jest.fn());
describe.skip("forgotPassword mutation", () => {
it("does not throw error if user doesn't exist", async () => {
await expect(forgotPassword({ email: "no-user@email.com" }, {} as Ctx)).resolves.not.toThrow();
});
it("works correctly", async () => {
// Create test user
const user = await db.user.create({
data: {
email: "user@example.com",
tokens: {
// Create old token to ensure it's deleted
create: {
type: "RESET_PASSWORD",
hashedToken: "token",
expiresAt: new Date(),
sentTo: "user@example.com",
},
},
},
include: { tokens: true },
});
// Invoke the mutation
await forgotPassword({ email: user.email }, {} as Ctx);
const tokens = await db.token.findMany({ where: { userId: user.id } });
const token = tokens[0];
if (!user.tokens[0]) throw new Error("Missing user token");
if (!token) throw new Error("Missing token");
// delete's existing tokens
expect(tokens.length).toBe(1);
expect(token.id).not.toBe(user.tokens[0].id);
expect(token.type).toBe("RESET_PASSWORD");
expect(token.sentTo).toBe(user.email);
expect(token.hashedToken).toBe(hash256(generatedToken));
expect(token.expiresAt > new Date()).toBe(true);
expect(previewEmail).toBeCalled();
});
});

View File

@ -1,75 +0,0 @@
import { hash256, SecurePassword } from "blitz";
import db from "../../../db";
import resetPassword from "./reset-password";
beforeEach(async () => {
await db.$reset();
});
const mockCtx: any = {
session: {
$create: jest.fn,
},
};
describe.skip("resetPassword mutation", () => {
it("works correctly", async () => {
expect(true).toBe(true);
// Create test user
const goodToken = "randomPasswordResetToken";
const expiredToken = "expiredRandomPasswordResetToken";
const future = new Date();
future.setHours(future.getHours() + 4);
const past = new Date();
past.setHours(past.getHours() - 4);
const user = await db.user.create({
data: {
email: "user@example.com",
tokens: {
// Create old token to ensure it's deleted
create: [
{
type: "RESET_PASSWORD",
hashedToken: hash256(expiredToken),
expiresAt: past,
sentTo: "user@example.com",
},
{
type: "RESET_PASSWORD",
hashedToken: hash256(goodToken),
expiresAt: future,
sentTo: "user@example.com",
},
],
},
},
include: { tokens: true },
});
const newPassword = "newPassword";
// Non-existent token
await expect(
resetPassword({ token: "no-token", password: "", passwordConfirmation: "" }, mockCtx),
).rejects.toThrowError();
// Expired token
await expect(
resetPassword({ token: expiredToken, password: newPassword, passwordConfirmation: newPassword }, mockCtx),
).rejects.toThrowError();
// Good token
await resetPassword({ token: goodToken, password: newPassword, passwordConfirmation: newPassword }, mockCtx);
// Delete's the token
const numberOfTokens = await db.token.count({ where: { userId: user.id } });
expect(numberOfTokens).toBe(0);
// Updates user's password
const updatedUser = await db.user.findFirst({ where: { id: user.id } });
expect(await SecurePassword.verify(updatedUser!.hashedPassword, newPassword)).toBe(SecurePassword.VALID);
});
});

View File

@ -1,39 +0,0 @@
import { GlobalRole } from "db";
import { render } from "../../test/utils";
import Home from "./index";
import useCurrentUser from "../core/hooks/use-current-user";
jest.mock("../core/hooks/use-current-user");
const mockUseCurrentUser = useCurrentUser as jest.MockedFunction<typeof useCurrentUser>;
test.skip("renders blitz documentation link", () => {
// This is an example of how to ensure a specific item is in the document
// But it's disabled by default (by test.skip) so the test doesn't fail
// when you remove the the default content from the page
// This is an example on how to mock api hooks when testing
mockUseCurrentUser.mockReturnValue({
organization: undefined,
user: {
id: uuidv4(),
name: "name",
email: "email@test.com",
role: GlobalRole.CUSTOMER,
memberships: [],
},
hasFilledTwilioCredentials: false,
hasCompletedOnboarding: undefined,
});
const { getByText } = render(<Home />);
const linkElement = getByText(/Documentation/i);
expect(linkElement).toBeInTheDocument();
});
function uuidv4() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}