Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 2s
553 lines
16 KiB
TypeScript
553 lines
16 KiB
TypeScript
import gql from 'graphql-tag';
|
|
import { makeGraphqlAPIRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';
|
|
import { uploadFileWithDirectUpload } from 'test/integration/graphql/utils/upload-file-with-direct-upload.util';
|
|
import { createOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata.util';
|
|
import { createOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/create-one-object-metadata.util';
|
|
import { deleteOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/delete-one-object-metadata.util';
|
|
import { updateOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/update-one-object-metadata.util';
|
|
import { makeMetadataAPIRequest } from 'test/integration/metadata/suites/utils/make-metadata-api-request.util';
|
|
import { FieldMetadataType } from 'twenty-shared/types';
|
|
|
|
const deleteFileMutation = gql`
|
|
mutation DeleteFile($fileId: UUID!) {
|
|
deleteFile(fileId: $fileId) {
|
|
id
|
|
}
|
|
}
|
|
`;
|
|
|
|
const createRecordsQuery = gql`
|
|
mutation CreateRecords(
|
|
$data: [FileSyncTestObjectCreateInput!]!
|
|
$upsert: Boolean
|
|
) {
|
|
createFileSyncTestObjects(data: $data, upsert: $upsert) {
|
|
id
|
|
name
|
|
filesField {
|
|
fileId
|
|
label
|
|
extension
|
|
url
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
const updateRecordQuery = gql`
|
|
mutation UpdateFileSyncTestObject(
|
|
$fileSyncTestObjectId: UUID!
|
|
$data: FileSyncTestObjectUpdateInput!
|
|
) {
|
|
updateFileSyncTestObject(id: $fileSyncTestObjectId, data: $data) {
|
|
id
|
|
name
|
|
filesField {
|
|
fileId
|
|
label
|
|
extension
|
|
url
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
const deleteRecordsQuery = gql`
|
|
mutation DeleteRecords($filter: FileSyncTestObjectFilterInput!) {
|
|
deleteFileSyncTestObjects(filter: $filter) {
|
|
id
|
|
}
|
|
}
|
|
`;
|
|
|
|
type UploadedFile = {
|
|
id: string;
|
|
contentType: string;
|
|
};
|
|
|
|
const deleteFile = async (fileId: string): Promise<void> => {
|
|
await makeMetadataAPIRequest({
|
|
query: deleteFileMutation,
|
|
variables: { fileId },
|
|
});
|
|
};
|
|
|
|
describe('fileFieldSync - FILES field <> files sync', () => {
|
|
let createdObjectMetadataId = '';
|
|
let createdFieldMetadataId = '';
|
|
let uploadedFiles: UploadedFile[] = [];
|
|
|
|
const uploadFile = async (
|
|
filename: string,
|
|
content: string,
|
|
contentType: string,
|
|
): Promise<UploadedFile> => {
|
|
const uploadedFile = await uploadFileWithDirectUpload({
|
|
filename,
|
|
content: Buffer.from(content),
|
|
fileFolder: 'FilesField',
|
|
fieldMetadataId: createdFieldMetadataId,
|
|
});
|
|
|
|
return {
|
|
id: uploadedFile.id,
|
|
contentType,
|
|
};
|
|
};
|
|
|
|
const checkFileExistsInDB = async (fileId: string): Promise<boolean> => {
|
|
const result = await global.testDataSource.query(
|
|
'SELECT id FROM core."file" WHERE id = $1 AND "deletedAt" IS NULL',
|
|
[fileId],
|
|
);
|
|
|
|
return result.length > 0;
|
|
};
|
|
|
|
const checkFileIsInPermanentStorage = async (
|
|
fileId: string,
|
|
): Promise<boolean> => {
|
|
const result = await global.testDataSource.query(
|
|
'SELECT settings FROM core."file" WHERE id = $1',
|
|
[fileId],
|
|
);
|
|
|
|
if (result.length === 0) {
|
|
return false;
|
|
}
|
|
|
|
return result[0].settings.isTemporaryFile === false;
|
|
};
|
|
|
|
const checkFileIsTemporary = async (fileId: string): Promise<boolean> => {
|
|
const result = await global.testDataSource.query(
|
|
'SELECT settings FROM core."file" WHERE id = $1',
|
|
[fileId],
|
|
);
|
|
|
|
if (result.length === 0) {
|
|
return false;
|
|
}
|
|
|
|
return result[0].settings.isTemporaryFile === true;
|
|
};
|
|
|
|
beforeAll(async () => {
|
|
jest.useRealTimers();
|
|
|
|
const {
|
|
data: {
|
|
createOneObject: { id: objectMetadataId },
|
|
},
|
|
} = await createOneObjectMetadata({
|
|
input: {
|
|
nameSingular: 'fileSyncTestObject',
|
|
namePlural: 'fileSyncTestObjects',
|
|
labelSingular: 'File Sync Test Object',
|
|
labelPlural: 'File Sync Test Objects',
|
|
icon: 'IconFile',
|
|
},
|
|
});
|
|
|
|
createdObjectMetadataId = objectMetadataId;
|
|
|
|
const {
|
|
data: {
|
|
createOneField: { id: fieldMetadataId },
|
|
},
|
|
} = await createOneFieldMetadata({
|
|
input: {
|
|
name: 'filesField',
|
|
label: 'Files Field',
|
|
type: FieldMetadataType.FILES,
|
|
objectMetadataId: createdObjectMetadataId,
|
|
settings: { maxNumberOfValues: 5 },
|
|
},
|
|
gqlFields: `
|
|
id
|
|
name
|
|
label
|
|
type
|
|
`,
|
|
});
|
|
|
|
createdFieldMetadataId = fieldMetadataId;
|
|
});
|
|
|
|
afterEach(async () => {
|
|
for (const file of uploadedFiles) {
|
|
await deleteFile(file.id);
|
|
}
|
|
uploadedFiles = [];
|
|
});
|
|
|
|
afterAll(async () => {
|
|
jest.useFakeTimers();
|
|
|
|
await updateOneObjectMetadata({
|
|
expectToFail: false,
|
|
input: {
|
|
idToUpdate: createdObjectMetadataId,
|
|
updatePayload: {
|
|
isActive: false,
|
|
},
|
|
},
|
|
});
|
|
await deleteOneObjectMetadata({
|
|
input: { idToDelete: createdObjectMetadataId },
|
|
});
|
|
});
|
|
|
|
it('createMany without upsert - files sync successfully', async () => {
|
|
const file1 = await uploadFile(
|
|
'test-file1.txt',
|
|
'fake text content',
|
|
'text/plain',
|
|
);
|
|
const file2 = await uploadFile(
|
|
'test-text.txt',
|
|
'fake text content',
|
|
'text/plain',
|
|
);
|
|
|
|
uploadedFiles.push(file1, file2);
|
|
|
|
expect(await checkFileExistsInDB(file1.id)).toBe(true);
|
|
expect(await checkFileExistsInDB(file2.id)).toBe(true);
|
|
expect(await checkFileIsTemporary(file1.id)).toBe(true);
|
|
expect(await checkFileIsTemporary(file2.id)).toBe(true);
|
|
|
|
const response = await makeGraphqlAPIRequest({
|
|
query: createRecordsQuery,
|
|
variables: {
|
|
data: [
|
|
{
|
|
name: 'Record with image',
|
|
filesField: [
|
|
{
|
|
fileId: file1.id,
|
|
label: 'test-file1.txt',
|
|
},
|
|
{
|
|
fileId: file2.id,
|
|
label: 'test-file2.txt',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
upsert: false,
|
|
},
|
|
});
|
|
|
|
expect(response.body.errors).toBeUndefined();
|
|
expect(response.body.data).toBeDefined();
|
|
|
|
const createdRecord = response.body.data.createFileSyncTestObjects[0];
|
|
|
|
expect(createdRecord.filesField).toHaveLength(2);
|
|
expect(createdRecord.filesField[0].fileId).toBe(file1.id);
|
|
expect(createdRecord.filesField[0].extension).toBe('.txt');
|
|
expect(createdRecord.filesField[1].fileId).toBe(file2.id);
|
|
expect(createdRecord.filesField[1].extension).toBe('.txt');
|
|
expect(createdRecord.filesField[0].url).toBeDefined();
|
|
expect(createdRecord.filesField[1].url).toBeDefined();
|
|
|
|
expect(await checkFileExistsInDB(file1.id)).toBe(true);
|
|
expect(await checkFileExistsInDB(file2.id)).toBe(true);
|
|
expect(await checkFileIsInPermanentStorage(file1.id)).toBe(true);
|
|
expect(await checkFileIsInPermanentStorage(file2.id)).toBe(true);
|
|
|
|
await makeGraphqlAPIRequest({
|
|
query: deleteRecordsQuery,
|
|
variables: {
|
|
filter: { id: { eq: createdRecord.id } },
|
|
},
|
|
});
|
|
});
|
|
|
|
it('createMany with upsert - files sync successfully', async () => {
|
|
const file1 = await uploadFile(
|
|
'test-file1.txt',
|
|
'fake text content',
|
|
'text/plain',
|
|
);
|
|
const file2 = await uploadFile(
|
|
'test-file2.txt',
|
|
'fake text content',
|
|
'text/plain',
|
|
);
|
|
const file3 = await uploadFile(
|
|
'test-file3.txt',
|
|
'fake text content',
|
|
'text/plain',
|
|
);
|
|
|
|
uploadedFiles.push(file1, file2, file3);
|
|
|
|
expect(await checkFileExistsInDB(file1.id)).toBe(true);
|
|
expect(await checkFileExistsInDB(file2.id)).toBe(true);
|
|
expect(await checkFileExistsInDB(file3.id)).toBe(true);
|
|
expect(await checkFileIsTemporary(file1.id)).toBe(true);
|
|
expect(await checkFileIsTemporary(file2.id)).toBe(true);
|
|
expect(await checkFileIsTemporary(file3.id)).toBe(true);
|
|
|
|
const createResponse = await makeGraphqlAPIRequest({
|
|
query: createRecordsQuery,
|
|
variables: {
|
|
data: [
|
|
{
|
|
name: 'Record to upsert',
|
|
filesField: [
|
|
{
|
|
fileId: file1.id,
|
|
label: 'test-file1.txt',
|
|
},
|
|
{
|
|
fileId: file2.id,
|
|
label: 'test-file2.txt',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
upsert: false,
|
|
},
|
|
});
|
|
|
|
const createdRecord = createResponse.body.data.createFileSyncTestObjects[0];
|
|
const recordId = createdRecord.id;
|
|
|
|
expect(createdRecord.filesField[0].extension).toBe('.txt');
|
|
|
|
const upsertResponse = await makeGraphqlAPIRequest({
|
|
query: createRecordsQuery,
|
|
variables: {
|
|
data: [
|
|
{
|
|
id: recordId,
|
|
name: 'Record updated via upsert',
|
|
filesField: [
|
|
{
|
|
fileId: file1.id,
|
|
label: 'updated-label-test-file1.txt',
|
|
},
|
|
{
|
|
fileId: file2.id,
|
|
label: 'test-file2.txt',
|
|
},
|
|
{
|
|
fileId: file3.id,
|
|
label: 'new-test-file3.txt',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
upsert: true,
|
|
},
|
|
});
|
|
|
|
expect(upsertResponse.body.errors).toBeUndefined();
|
|
|
|
const updatedRecord = upsertResponse.body.data.createFileSyncTestObjects[0];
|
|
|
|
expect(updatedRecord.id).toBe(recordId);
|
|
expect(updatedRecord.name).toBe('Record updated via upsert');
|
|
expect(updatedRecord.filesField).toHaveLength(3);
|
|
expect(updatedRecord.filesField[1].fileId).toBe(file2.id);
|
|
expect(updatedRecord.filesField[1].label).toBe('test-file2.txt');
|
|
expect(updatedRecord.filesField[1].extension).toBe('.txt');
|
|
expect(updatedRecord.filesField[1].url).toBeDefined();
|
|
expect(updatedRecord.filesField[2].fileId).toBe(file3.id);
|
|
expect(updatedRecord.filesField[2].label).toBe('new-test-file3.txt');
|
|
expect(updatedRecord.filesField[2].extension).toBe('.txt');
|
|
expect(updatedRecord.filesField[2].url).toBeDefined();
|
|
expect(updatedRecord.filesField[0].fileId).toBe(file1.id);
|
|
expect(updatedRecord.filesField[0].label).toBe(
|
|
'updated-label-test-file1.txt',
|
|
);
|
|
expect(updatedRecord.filesField[0].extension).toBe('.txt');
|
|
expect(updatedRecord.filesField[0].url).toBeDefined();
|
|
|
|
expect(await checkFileIsInPermanentStorage(file1.id)).toBe(true);
|
|
expect(await checkFileIsInPermanentStorage(file2.id)).toBe(true);
|
|
expect(await checkFileIsInPermanentStorage(file3.id)).toBe(true);
|
|
|
|
await makeGraphqlAPIRequest({
|
|
query: deleteRecordsQuery,
|
|
variables: {
|
|
filter: { id: { eq: recordId } },
|
|
},
|
|
});
|
|
});
|
|
|
|
it('updateOne - files sync successfully', async () => {
|
|
const file1 = await uploadFile(
|
|
'test-file1.txt',
|
|
'fake text content',
|
|
'text/plain',
|
|
);
|
|
const file2 = await uploadFile(
|
|
'test-file2.txt',
|
|
'fake text content',
|
|
'text/plain',
|
|
);
|
|
|
|
uploadedFiles.push(file1, file2);
|
|
|
|
expect(await checkFileExistsInDB(file1.id)).toBe(true);
|
|
expect(await checkFileExistsInDB(file2.id)).toBe(true);
|
|
expect(await checkFileIsTemporary(file1.id)).toBe(true);
|
|
expect(await checkFileIsTemporary(file2.id)).toBe(true);
|
|
|
|
const createResponse = await makeGraphqlAPIRequest({
|
|
query: createRecordsQuery,
|
|
variables: {
|
|
data: [
|
|
{
|
|
name: 'Record for updateOne test',
|
|
filesField: [
|
|
{
|
|
fileId: file1.id,
|
|
label: 'test-file1.txt',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
upsert: false,
|
|
},
|
|
});
|
|
|
|
expect(await checkFileIsInPermanentStorage(file1.id)).toBe(true);
|
|
|
|
const createdRecord = createResponse.body.data.createFileSyncTestObjects[0];
|
|
const recordId = createdRecord.id;
|
|
|
|
expect(createdRecord.filesField[0].extension).toBe('.txt');
|
|
|
|
const updateResponse = await makeGraphqlAPIRequest({
|
|
query: updateRecordQuery,
|
|
variables: {
|
|
fileSyncTestObjectId: recordId,
|
|
data: {
|
|
name: 'Record updated via updateOne',
|
|
filesField: [
|
|
{
|
|
fileId: file1.id,
|
|
label: 'added-text.txt',
|
|
},
|
|
{
|
|
fileId: file2.id,
|
|
label: 'test-file2.txt',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(updateResponse.body.errors).toBeUndefined();
|
|
|
|
const updatedRecord = updateResponse.body.data.updateFileSyncTestObject;
|
|
|
|
expect(updatedRecord.id).toBe(recordId);
|
|
expect(updatedRecord.name).toBe('Record updated via updateOne');
|
|
expect(updatedRecord.filesField).toHaveLength(2);
|
|
expect(updatedRecord.filesField[1].fileId).toBe(file2.id);
|
|
expect(updatedRecord.filesField[1].label).toBe('test-file2.txt');
|
|
expect(updatedRecord.filesField[1].url).toBeDefined();
|
|
expect(updatedRecord.filesField[0].fileId).toBe(file1.id);
|
|
expect(updatedRecord.filesField[0].label).toBe('added-text.txt');
|
|
expect(updatedRecord.filesField[0].url).toBeDefined();
|
|
expect(await checkFileExistsInDB(file1.id)).toBe(true);
|
|
expect(await checkFileExistsInDB(file2.id)).toBe(true);
|
|
expect(await checkFileIsInPermanentStorage(file1.id)).toBe(true);
|
|
expect(await checkFileIsInPermanentStorage(file2.id)).toBe(true);
|
|
|
|
await makeGraphqlAPIRequest({
|
|
query: deleteRecordsQuery,
|
|
variables: {
|
|
filter: { id: { eq: recordId } },
|
|
},
|
|
});
|
|
});
|
|
|
|
it('updateOne with removeFiles - verifies files can be removed', async () => {
|
|
const file1 = await uploadFile(
|
|
'test-file1.txt',
|
|
'fake text content',
|
|
'text/plain',
|
|
);
|
|
const file2 = await uploadFile(
|
|
'test-file2.txt',
|
|
'fake text content',
|
|
'text/plain',
|
|
);
|
|
|
|
uploadedFiles.push(file1, file2);
|
|
|
|
expect(await checkFileExistsInDB(file1.id)).toBe(true);
|
|
expect(await checkFileExistsInDB(file2.id)).toBe(true);
|
|
expect(await checkFileIsTemporary(file1.id)).toBe(true);
|
|
expect(await checkFileIsTemporary(file2.id)).toBe(true);
|
|
|
|
const createResponse = await makeGraphqlAPIRequest({
|
|
query: createRecordsQuery,
|
|
variables: {
|
|
data: [
|
|
{
|
|
name: 'Record for file deletion test',
|
|
filesField: [
|
|
{
|
|
fileId: file1.id,
|
|
label: 'test-file1.txt',
|
|
},
|
|
{
|
|
fileId: file2.id,
|
|
label: 'text-to-keep.txt',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
upsert: false,
|
|
},
|
|
});
|
|
|
|
expect(await checkFileIsInPermanentStorage(file1.id)).toBe(true);
|
|
expect(await checkFileIsInPermanentStorage(file2.id)).toBe(true);
|
|
|
|
const createdRecord = createResponse.body.data.createFileSyncTestObjects[0];
|
|
const recordId = createdRecord.id;
|
|
|
|
const updateResponse = await makeGraphqlAPIRequest({
|
|
query: updateRecordQuery,
|
|
variables: {
|
|
fileSyncTestObjectId: recordId,
|
|
data: {
|
|
filesField: [
|
|
{
|
|
fileId: file2.id,
|
|
label: 'text-to-keep.txt',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(updateResponse.body.errors).toBeUndefined();
|
|
|
|
const updatedRecord = updateResponse.body.data.updateFileSyncTestObject;
|
|
|
|
expect(updatedRecord.filesField).toHaveLength(1);
|
|
expect(updatedRecord.filesField[0].fileId).toBe(file2.id);
|
|
|
|
expect(await checkFileExistsInDB(file1.id)).toBe(false);
|
|
expect(await checkFileExistsInDB(file2.id)).toBe(true);
|
|
expect(await checkFileIsInPermanentStorage(file2.id)).toBe(true);
|
|
|
|
await makeGraphqlAPIRequest({
|
|
query: deleteRecordsQuery,
|
|
variables: {
|
|
filter: { id: { eq: recordId } },
|
|
},
|
|
});
|
|
});
|
|
});
|