Skip to content

Commit

Permalink
implementation (#6468)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaszloKecskes authored Feb 13, 2024
1 parent 2665902 commit 82d859a
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/api/migrations/migrations/158-reindex/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Db } from 'mongodb';

export default {
delta: 158,

name: 'reindex',

description:
'A previous PR missed a reindex, this migration is an empty migration that only signals a reindex.',

reindex: true,

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async up(db: Db) {
process.stdout.write(`${this.name}...\r\n`);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Db } from 'mongodb';

import testingDB from 'api/utils/testing_db';
import migration from '../index';
import { Fixture } from '../types';
import { fixtures } from './fixtures';

let db: Db | null;

const initTest = async (fixture: Fixture) => {
await testingDB.setupFixturesAndContext(fixture);
db = testingDB.mongodb!;
await migration.up(db);
};

beforeAll(async () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
jest.spyOn(process.stdout, 'write').mockImplementation((str: string | Uint8Array) => true);
});

afterAll(async () => {
await testingDB.tearDown();
});

describe('migration test', () => {
beforeAll(async () => {
await initTest(fixtures);
});

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

it('should check if a reindex is needed', async () => {
expect(migration.reindex).toBe(true);
});
});
13 changes: 13 additions & 0 deletions app/api/migrations/migrations/158-reindex/specs/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ObjectId } from 'mongodb';
import { Fixture } from '../types';

const fixtures: Fixture = {
entities: [
{
_id: new ObjectId(),
title: 'test_doc',
},
],
};

export { fixtures };
13 changes: 13 additions & 0 deletions app/api/migrations/migrations/158-reindex/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ObjectId } from 'mongodb';

interface Entity {
_id: ObjectId;
title: string;
[k: string]: unknown | undefined;
}

interface Fixture {
entities: Entity[];
}

export type { Entity, Fixture };

0 comments on commit 82d859a

Please sign in to comment.