chore: format
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { prisma } from "@src/utils/prisma"
|
||||
import { prisma } from "@src/utils/prisma";
|
||||
|
||||
type ListOptions = {
|
||||
name: string
|
||||
organizationId: string
|
||||
description?: string
|
||||
}
|
||||
name: string;
|
||||
organizationId: string;
|
||||
description?: string;
|
||||
};
|
||||
|
||||
export const createList = async (data: ListOptions) => {
|
||||
return prisma.list.create({ data })
|
||||
}
|
||||
return prisma.list.create({ data });
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { app } from "@src/app"
|
||||
import superTest from "supertest"
|
||||
import { app } from "@src/app";
|
||||
import superTest from "supertest";
|
||||
|
||||
export const request = superTest(app)
|
||||
export const request = superTest(app);
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import { prisma } from "@src/utils/prisma"
|
||||
import { prisma } from "@src/utils/prisma";
|
||||
|
||||
export default async () => {
|
||||
await prisma.$transaction([
|
||||
prisma.organization.deleteMany(),
|
||||
prisma.user.deleteMany(),
|
||||
prisma.userOrganization.deleteMany(),
|
||||
prisma.subscriber.deleteMany(),
|
||||
prisma.campaign.deleteMany(),
|
||||
prisma.list.deleteMany(),
|
||||
prisma.campaignList.deleteMany(),
|
||||
prisma.listSubscriber.deleteMany(),
|
||||
prisma.template.deleteMany(),
|
||||
prisma.message.deleteMany(),
|
||||
prisma.trackedLink.deleteMany(),
|
||||
prisma.click.deleteMany(),
|
||||
prisma.apiKey.deleteMany(),
|
||||
prisma.smtpSettings.deleteMany(),
|
||||
prisma.generalSettings.deleteMany(),
|
||||
prisma.emailDeliverySettings.deleteMany(),
|
||||
])
|
||||
}
|
||||
await prisma.$transaction([
|
||||
prisma.organization.deleteMany(),
|
||||
prisma.user.deleteMany(),
|
||||
prisma.userOrganization.deleteMany(),
|
||||
prisma.subscriber.deleteMany(),
|
||||
prisma.campaign.deleteMany(),
|
||||
prisma.list.deleteMany(),
|
||||
prisma.campaignList.deleteMany(),
|
||||
prisma.listSubscriber.deleteMany(),
|
||||
prisma.template.deleteMany(),
|
||||
prisma.message.deleteMany(),
|
||||
prisma.trackedLink.deleteMany(),
|
||||
prisma.click.deleteMany(),
|
||||
prisma.apiKey.deleteMany(),
|
||||
prisma.smtpSettings.deleteMany(),
|
||||
prisma.generalSettings.deleteMany(),
|
||||
prisma.emailDeliverySettings.deleteMany(),
|
||||
]);
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { config } from "dotenv"
|
||||
config({ path: ".env.test" })
|
||||
import resetDb from "./reset-db"
|
||||
import { beforeEach } from "vitest"
|
||||
import { execSync } from "child_process"
|
||||
import { config } from "dotenv";
|
||||
config({ path: ".env.test" });
|
||||
import resetDb from "./reset-db";
|
||||
import { beforeEach } from "vitest";
|
||||
import { execSync } from "child_process";
|
||||
|
||||
execSync("prisma migrate deploy", { stdio: "ignore" })
|
||||
execSync("prisma migrate deploy", { stdio: "ignore" });
|
||||
|
||||
beforeEach(async () => {
|
||||
// await resetDb()
|
||||
})
|
||||
// await resetDb()
|
||||
});
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
import { hashPassword } from "@src/utils/auth"
|
||||
import { faker } from "@faker-js/faker"
|
||||
import { prisma } from "@src/utils/prisma"
|
||||
import { hashPassword } from "@src/utils/auth";
|
||||
import { faker } from "@faker-js/faker";
|
||||
import { prisma } from "@src/utils/prisma";
|
||||
|
||||
export async function createUser() {
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
name: faker.person.fullName(),
|
||||
email: faker.internet.email(),
|
||||
password: await hashPassword("password123"),
|
||||
UserOrganizations: {
|
||||
create: {
|
||||
Organization: {
|
||||
create: {
|
||||
name: faker.company.name(),
|
||||
description: faker.lorem.sentence(),
|
||||
GeneralSettings: {
|
||||
create: {},
|
||||
},
|
||||
EmailDeliverySettings: {
|
||||
create: {
|
||||
rateLimit: 100,
|
||||
},
|
||||
},
|
||||
SmtpSettings: {
|
||||
create: {
|
||||
host: "smtp.test.com",
|
||||
port: 587,
|
||||
username: "test",
|
||||
password: "test",
|
||||
encryption: "STARTTLS",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
UserOrganizations: {
|
||||
select: {
|
||||
organizationId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
name: faker.person.fullName(),
|
||||
email: faker.internet.email(),
|
||||
password: await hashPassword("password123"),
|
||||
UserOrganizations: {
|
||||
create: {
|
||||
Organization: {
|
||||
create: {
|
||||
name: faker.company.name(),
|
||||
description: faker.lorem.sentence(),
|
||||
GeneralSettings: {
|
||||
create: {},
|
||||
},
|
||||
EmailDeliverySettings: {
|
||||
create: {
|
||||
rateLimit: 100,
|
||||
},
|
||||
},
|
||||
SmtpSettings: {
|
||||
create: {
|
||||
host: "smtp.test.com",
|
||||
port: 587,
|
||||
username: "test",
|
||||
password: "test",
|
||||
encryption: "STARTTLS",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
UserOrganizations: {
|
||||
select: {
|
||||
organizationId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const orgId = user.UserOrganizations[0]?.organizationId || ""
|
||||
if (!orgId) {
|
||||
throw new Error("Organization not found")
|
||||
}
|
||||
const orgId = user.UserOrganizations[0]?.organizationId || "";
|
||||
if (!orgId) {
|
||||
throw new Error("Organization not found");
|
||||
}
|
||||
|
||||
// New API Key
|
||||
const apiKey = await prisma.apiKey.create({
|
||||
data: {
|
||||
key: faker.string.uuid(),
|
||||
name: "Test API Key",
|
||||
Organization: {
|
||||
connect: {
|
||||
id: orgId,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
key: true,
|
||||
},
|
||||
})
|
||||
// New API Key
|
||||
const apiKey = await prisma.apiKey.create({
|
||||
data: {
|
||||
key: faker.string.uuid(),
|
||||
name: "Test API Key",
|
||||
Organization: {
|
||||
connect: {
|
||||
id: orgId,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
key: true,
|
||||
},
|
||||
});
|
||||
|
||||
return { user, apiKey, orgId }
|
||||
return { user, apiKey, orgId };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user