-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
LaszloKecskes
authored
Feb 13, 2024
1 parent
2665902
commit 82d859a
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
}, | ||
}; |
37 changes: 37 additions & 0 deletions
37
app/api/migrations/migrations/158-reindex/specs/158-reindex.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
app/api/migrations/migrations/158-reindex/specs/fixtures.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |