Skip to content

The open alternative to Salesforce, designed for AI.

2.5 KB
Raw Blame
import { buildBaseManifest } from 'test/integration/metadata/suites/application/utils/build-base-manifest.util';
import { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/suites/application/utils/cleanup-application-and-app-registration.util';
import { createAppTarball } from 'test/integration/metadata/suites/application/utils/create-app-tarball.util';
import { installApplication } from 'test/integration/metadata/suites/application/utils/install-application.util';
import { uploadAppTarball } from 'test/integration/metadata/suites/application/utils/upload-app-tarball.util';
import {
  APPLICATION_PACKAGE_YARN_LOCK_PATH,
  computeDependencyFileChecksum,
} from 'twenty-shared/application';
import { v4 as uuidv4 } from 'uuid';

import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';

jest.setTimeout(120000);

const PACKAGED_YARN_LOCK = `# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
`;

describe('Install application with a packaged yarn.lock', () => {
  let universalIdentifier: string;

  beforeAll(() => {
    jest.useRealTimers();
  });

  beforeEach(() => {
    universalIdentifier = uuidv4();
  });

  afterEach(async () => {
    await cleanupApplicationAndAppRegistration({
      applicationUniversalIdentifier: universalIdentifier,
    });
  });

  afterAll(() => {
    jest.useFakeTimers();
  });

  it('stores the packaged yarn.lock as the application yarn.lock', async () => {
    const tarball = await createAppTarball({
      'manifest.json': JSON.stringify(
        buildBaseManifest({ appId: universalIdentifier, roleId: uuidv4() }),
      ),
      'package.json': JSON.stringify({
        name: `test-install-packaged-yarn-lock-${universalIdentifier}`,
        version: '1.0.0',
      }),
      [APPLICATION_PACKAGE_YARN_LOCK_PATH]: PACKAGED_YARN_LOCK,
    });

    const uploadResult = await uploadAppTarball({
      tarballBuffer: tarball,
      universalIdentifier,
    });

    expect(uploadResult.errors).toBeUndefined();

    const { errors } = await installApplication({
      input: { universalIdentifier },
      expectToFail: false,
    });

    expect(errors).toBeUndefined();

    const [application] = await global.testDataSource.query(
      `SELECT "yarnLockChecksum" FROM core."application"
       WHERE "universalIdentifier" = $1 AND "workspaceId" = $2`,
      [universalIdentifier, SEED_APPLE_WORKSPACE_ID],
    );

    expect(application.yarnLockChecksum).toBe(
      computeDependencyFileChecksum(PACKAGED_YARN_LOCK),
    );
  });
});