fix: refactor prisma relations (#1581)

This commit is contained in:
David Nguyen
2025-01-13 13:41:53 +11:00
committed by GitHub
parent 48b55758e3
commit 7d0a9c6439
143 changed files with 687 additions and 790 deletions

View File

@ -28,7 +28,7 @@ test('[DOCUMENT_AUTH]: should allow signing when no auth setup', async ({ page }
// Check that both are granted access.
for (const recipient of recipients) {
const { token, Field } = recipient;
const { token, fields } = recipient;
const signUrl = `/sign/${token}`;
@ -45,7 +45,7 @@ test('[DOCUMENT_AUTH]: should allow signing when no auth setup', async ({ page }
await page.mouse.up();
}
for (const field of Field) {
for (const field of fields) {
await page.locator(`#field-${field.id}`).getByRole('button').click();
if (field.type === FieldType.TEXT) {
@ -80,7 +80,7 @@ test('[DOCUMENT_AUTH]: should allow signing with valid global auth', async ({ pa
const recipient = recipients[0];
const { token, Field } = recipient;
const { token, fields } = recipient;
const signUrl = `/sign/${token}`;
@ -102,7 +102,7 @@ test('[DOCUMENT_AUTH]: should allow signing with valid global auth', async ({ pa
await page.mouse.up();
}
for (const field of Field) {
for (const field of fields) {
await page.locator(`#field-${field.id}`).getByRole('button').click();
if (field.type === FieldType.TEXT) {
@ -170,12 +170,12 @@ test('[DOCUMENT_AUTH]: should deny signing fields when required for global auth'
// Check that both are denied access.
for (const recipient of recipients) {
const { token, Field } = recipient;
const { token, fields } = recipient;
await page.goto(`/sign/${token}`);
await expect(page.getByRole('heading', { name: 'Sign Document' })).toBeVisible();
for (const field of Field) {
for (const field of fields) {
if (field.type !== FieldType.SIGNATURE) {
continue;
}
@ -229,7 +229,7 @@ test('[DOCUMENT_AUTH]: should allow field signing when required for recipient au
});
for (const recipient of recipients) {
const { token, Field } = recipient;
const { token, fields } = recipient;
const { actionAuth } = ZRecipientAuthOptionsSchema.parse(recipient.authOptions);
// This document has no global action auth, so only account should require auth.
@ -241,7 +241,7 @@ test('[DOCUMENT_AUTH]: should allow field signing when required for recipient au
await expect(page.getByRole('heading', { name: 'Sign Document' })).toBeVisible();
if (isAuthRequired) {
for (const field of Field) {
for (const field of fields) {
if (field.type !== FieldType.SIGNATURE) {
continue;
}
@ -271,7 +271,7 @@ test('[DOCUMENT_AUTH]: should allow field signing when required for recipient au
await page.mouse.up();
}
for (const field of Field) {
for (const field of fields) {
await page.locator(`#field-${field.id}`).getByRole('button').click();
if (field.type === FieldType.TEXT) {
@ -340,7 +340,7 @@ test('[DOCUMENT_AUTH]: should allow field signing when required for recipient an
});
for (const recipient of recipients) {
const { token, Field } = recipient;
const { token, fields } = recipient;
const { actionAuth } = ZRecipientAuthOptionsSchema.parse(recipient.authOptions);
// This document HAS global action auth, so account and inherit should require auth.
@ -352,7 +352,7 @@ test('[DOCUMENT_AUTH]: should allow field signing when required for recipient an
await expect(page.getByRole('heading', { name: 'Sign Document' })).toBeVisible();
if (isAuthRequired) {
for (const field of Field) {
for (const field of fields) {
if (field.type !== FieldType.SIGNATURE) {
continue;
}
@ -382,7 +382,7 @@ test('[DOCUMENT_AUTH]: should allow field signing when required for recipient an
await page.mouse.up();
}
for (const field of Field) {
for (const field of fields) {
await page.locator(`#field-${field.id}`).getByRole('button').click();
if (field.type === FieldType.TEXT) {

View File

@ -24,7 +24,7 @@ import { apiSignin } from '../fixtures/authentication';
const getDocumentByToken = async (token: string) => {
return await prisma.document.findFirstOrThrow({
where: {
Recipient: {
recipients: {
some: {
token,
},
@ -357,7 +357,7 @@ test('[DOCUMENT_FLOW]: should be able to approve a document', async ({ page }) =
});
for (const recipient of recipients) {
const { token, Field, role } = recipient;
const { token, fields, role } = recipient;
const signUrl = `/sign/${token}`;
@ -378,7 +378,7 @@ test('[DOCUMENT_FLOW]: should be able to approve a document', async ({ page }) =
await page.mouse.up();
}
for (const field of Field) {
for (const field of fields) {
await page.locator(`#field-${field.id}`).getByRole('button').click();
await expect(page.locator(`#field-${field.id}`)).toHaveAttribute('data-inserted', 'true');
@ -479,8 +479,8 @@ test('[DOCUMENT_FLOW]: should be able to sign a document with custom date', asyn
fields: [FieldType.DATE],
});
const { token, Field } = recipients[0];
const [recipientField] = Field;
const { token, fields } = recipients[0];
const [recipientField] = fields;
await page.goto(`/sign/${token}`);
await page.waitForURL(`/sign/${token}`);
@ -496,7 +496,7 @@ test('[DOCUMENT_FLOW]: should be able to sign a document with custom date', asyn
const field = await prisma.field.findFirst({
where: {
Recipient: {
recipient: {
email: 'user1@example.com',
},
documentId: Number(document.id),
@ -580,14 +580,14 @@ test('[DOCUMENT_FLOW]: should be able to create and sign a document with 3 recip
const createdDocument = await prisma.document.findFirst({
where: { title: documentTitle },
include: { Recipient: true },
include: { recipients: true },
});
expect(createdDocument).not.toBeNull();
expect(createdDocument?.Recipient.length).toBe(3);
expect(createdDocument?.recipients.length).toBe(3);
for (let i = 0; i < 3; i++) {
const recipient = createdDocument?.Recipient.find(
const recipient = createdDocument?.recipients.find(
(r) => r.email === `user${i + 1}@example.com`,
);
expect(recipient).not.toBeNull();

View File

@ -129,7 +129,7 @@ test('[DOCUMENTS]: deleting a pending document should remove it from recipients'
// signout
await apiSignout({ page });
for (const recipient of pendingDocument.Recipient) {
for (const recipient of pendingDocument.recipients) {
await apiSignin({
page,
email: recipient.email,

View File

@ -45,7 +45,7 @@ test.describe('Signing Certificate Tests', () => {
await page.mouse.up();
}
for (const field of recipient.Field) {
for (const field of recipient.fields) {
await page.locator(`#field-${field.id}`).getByRole('button').click();
await expect(page.locator(`#field-${field.id}`)).toHaveAttribute('data-inserted', 'true');
@ -122,7 +122,7 @@ test.describe('Signing Certificate Tests', () => {
await page.mouse.up();
}
for (const field of recipient.Field) {
for (const field of recipient.fields) {
await page.locator(`#field-${field.id}`).getByRole('button').click();
await expect(page.locator(`#field-${field.id}`)).toHaveAttribute('data-inserted', 'true');
@ -199,7 +199,7 @@ test.describe('Signing Certificate Tests', () => {
await page.mouse.up();
}
for (const field of recipient.Field) {
for (const field of recipient.fields) {
await page.locator(`#field-${field.id}`).getByRole('button').click();
await expect(page.locator(`#field-${field.id}`)).toHaveAttribute('data-inserted', 'true');

View File

@ -124,7 +124,7 @@ test('[TEMPLATE]: should create a document from a template', async ({ page }) =>
id: documentId,
},
include: {
Recipient: true,
recipients: true,
documentMeta: true,
},
});
@ -144,8 +144,8 @@ test('[TEMPLATE]: should create a document from a template', async ({ page }) =>
expect(document.documentMeta?.subject).toEqual('SUBJECT');
expect(document.documentMeta?.timezone).toEqual('Etc/UTC');
const recipientOne = document.Recipient[0];
const recipientTwo = document.Recipient[1];
const recipientOne = document.recipients[0];
const recipientTwo = document.recipients[1];
const recipientOneAuth = extractDocumentAuthMethods({
documentAuth: document.authOptions,
@ -259,7 +259,7 @@ test('[TEMPLATE]: should create a team document from a team template', async ({
id: documentId,
},
include: {
Recipient: true,
recipients: true,
documentMeta: true,
},
});
@ -281,8 +281,8 @@ test('[TEMPLATE]: should create a team document from a team template', async ({
expect(document.documentMeta?.subject).toEqual('SUBJECT');
expect(document.documentMeta?.timezone).toEqual('Etc/UTC');
const recipientOne = document.Recipient[0];
const recipientTwo = document.Recipient[1];
const recipientOne = document.recipients[0];
const recipientTwo = document.recipients[1];
const recipientOneAuth = extractDocumentAuthMethods({
documentAuth: document.authOptions,

View File

@ -260,7 +260,7 @@ test('[DIRECT_TEMPLATES]: use direct template link with 2 recipients', async ({
const secondRecipient = await seedUser();
const createTemplateOptions = {
Recipient: {
recipients: {
createMany: {
data: [
{