mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
This PR is handles the changes required to support envelopes. The new envelope editor/signing page will be hidden during release. The core changes here is to migrate the documents and templates model to a centralized envelopes model. Even though Documents and Templates are removed, from the user perspective they will still exist as we remap envelopes to documents and templates.
149 lines
4.3 KiB
TypeScript
149 lines
4.3 KiB
TypeScript
import { expect, test } from '@playwright/test';
|
|
|
|
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
|
import { createApiToken } from '@documenso/lib/server-only/public-api/create-api-token';
|
|
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
|
import { prisma } from '@documenso/prisma';
|
|
import { seedPendingDocumentWithFullFields } from '@documenso/prisma/seed/documents';
|
|
import { seedUser } from '@documenso/prisma/seed/users';
|
|
|
|
test.describe('Document API', () => {
|
|
test('sendDocument: should respect sendCompletionEmails setting', async ({ request }) => {
|
|
const { user, team } = await seedUser();
|
|
|
|
const { document } = await seedPendingDocumentWithFullFields({
|
|
owner: user,
|
|
recipients: ['signer@example.com'],
|
|
teamId: team.id,
|
|
});
|
|
|
|
const { token } = await createApiToken({
|
|
userId: user.id,
|
|
teamId: team.id,
|
|
tokenName: 'test',
|
|
expiresIn: null,
|
|
});
|
|
|
|
// Test with sendCompletionEmails: false
|
|
const response = await request.post(
|
|
`${NEXT_PUBLIC_WEBAPP_URL()}/api/v1/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/send`,
|
|
{
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
data: {
|
|
sendCompletionEmails: false,
|
|
},
|
|
},
|
|
);
|
|
|
|
expect(response.ok()).toBeTruthy();
|
|
expect(response.status()).toBe(200);
|
|
|
|
// Verify email settings were updated
|
|
const updatedDocument = await prisma.envelope.findUnique({
|
|
where: { id: document.id },
|
|
include: { documentMeta: true },
|
|
});
|
|
|
|
expect(updatedDocument?.documentMeta?.emailSettings).toMatchObject({
|
|
documentCompleted: false,
|
|
ownerDocumentCompleted: false,
|
|
});
|
|
|
|
// Test with sendCompletionEmails: true
|
|
const response2 = await request.post(
|
|
`${NEXT_PUBLIC_WEBAPP_URL()}/api/v1/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/send`,
|
|
{
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
data: {
|
|
sendCompletionEmails: true,
|
|
},
|
|
},
|
|
);
|
|
|
|
expect(response2.ok()).toBeTruthy();
|
|
expect(response2.status()).toBe(200);
|
|
|
|
// Verify email settings were updated
|
|
const updatedDocument2 = await prisma.envelope.findUnique({
|
|
where: { id: document.id },
|
|
include: { documentMeta: true },
|
|
});
|
|
|
|
expect(updatedDocument2?.documentMeta?.emailSettings ?? {}).toMatchObject({
|
|
documentCompleted: true,
|
|
ownerDocumentCompleted: true,
|
|
});
|
|
});
|
|
|
|
test('sendDocument: should not modify email settings when sendCompletionEmails is not provided', async ({
|
|
request,
|
|
}) => {
|
|
const { user, team } = await seedUser();
|
|
|
|
const { document } = await seedPendingDocumentWithFullFields({
|
|
owner: user,
|
|
recipients: ['signer@example.com'],
|
|
teamId: team.id,
|
|
});
|
|
|
|
// Set initial email settings
|
|
await prisma.documentMeta.upsert({
|
|
where: { id: document.documentMetaId },
|
|
create: {
|
|
id: document.documentMetaId,
|
|
emailSettings: {
|
|
documentCompleted: true,
|
|
ownerDocumentCompleted: false,
|
|
},
|
|
},
|
|
update: {
|
|
id: document.documentMetaId,
|
|
emailSettings: {
|
|
documentCompleted: true,
|
|
ownerDocumentCompleted: false,
|
|
},
|
|
},
|
|
});
|
|
|
|
const { token } = await createApiToken({
|
|
userId: user.id,
|
|
teamId: team.id,
|
|
tokenName: 'test',
|
|
expiresIn: null,
|
|
});
|
|
|
|
const response = await request.post(
|
|
`${NEXT_PUBLIC_WEBAPP_URL()}/api/v1/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/send`,
|
|
{
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
data: {
|
|
sendEmail: true,
|
|
},
|
|
},
|
|
);
|
|
|
|
expect(response.ok()).toBeTruthy();
|
|
expect(response.status()).toBe(200);
|
|
|
|
// Verify email settings were not modified
|
|
const updatedDocument = await prisma.envelope.findUnique({
|
|
where: { id: document.id },
|
|
include: { documentMeta: true },
|
|
});
|
|
|
|
expect(updatedDocument?.documentMeta?.emailSettings ?? {}).toMatchObject({
|
|
documentCompleted: true,
|
|
ownerDocumentCompleted: false,
|
|
});
|
|
});
|
|
});
|