{"size": 946, "ext": "js", "max_stars_repo_path": "app/api/migrations/migrations/20-custom-uploads-type/specs/20-custom-uploads-type.spec.js", "max_stars_repo_name": "N07070/uwazi", "max_stars_repo_stars_event_min_datetime": "2021-11-01T10:16:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T08:35:45.000Z", "max_issues_repo_path": "app/api/migrations/migrations/20-custom-uploads-type/specs/20-custom-uploads-type.spec.js", "max_issues_repo_name": "N07070/uwazi", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/api/migrations/migrations/20-custom-uploads-type/specs/20-custom-uploads-type.spec.js", "max_forks_repo_name": "N07070/uwazi", "max_forks_repo_forks_event_min_datetime": "2022-01-02T14:58:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-02T14:58:09.000Z"}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 25.5675675676, "max_line_length": 73, "alphanum_fraction": 0.6257928118}
import { catchErrors } from 'api/utils/jasmineHelpers';
import testingDB from 'api/utils/testing_db';
import migration from '../index.js';
import fixtures from './fixtures.js';

describe('migration custom-uploads-type', () => {
  beforeEach(done => {
    spyOn(process.stdout, 'write');
    testingDB
      .clearAllAndLoad(fixtures)
      .then(done)
      .catch(catchErrors(done));
  });

  afterAll(done => {
    testingDB.disconnect().then(done);
  });

  it('should have a delta number', () => {
    expect(migration.delta).toBe(20);
  });

  it('should add type="custom" to all files', async () => {
    await migration.up(testingDB.mongodb);

    const files = await testingDB.mongodb
      .collection('files')
      .find()
      .toArray();

    expect(files).toEqual([
      expect.objectContaining({ filename: 'test.txt', type: 'custom' }),
      expect.objectContaining({ filename: 'test2.txt', type: 'custom' }),
    ]);
  });
});
