Skip to content

Commit b9e2906

Browse files
UTs
1 parent a962217 commit b9e2906

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

packages/backend/src/db.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { expect, test } from 'vitest';
2+
import { migration_addFileLimitSize, migration_addSettings, Schema } from './db';
3+
import { DEFAULT_SETTINGS } from './constants';
4+
import { DeepPartial } from './types';
5+
6+
7+
test('migration_addSettings adds the `settings` field with defaults if it does not exist', () => {
8+
const schema: DeepPartial<Schema> = {};
9+
10+
const migratedSchema = migration_addSettings(schema as Schema);
11+
expect(migratedSchema).toStrictEqual({
12+
settings: DEFAULT_SETTINGS,
13+
});
14+
});
15+
16+
test('migration_addFileLimitSize adds the `fileLimitSize` field with the default value if it does not exist', () => {
17+
const schema: DeepPartial<Schema> = {
18+
settings: {},
19+
}
20+
21+
const migratedSchema = migration_addFileLimitSize(schema as Schema);
22+
expect(migratedSchema).toStrictEqual({
23+
settings: {
24+
fileLimitSize: DEFAULT_SETTINGS.fileLimitSize,
25+
}
26+
});
27+
});
28+
29+
test('migration_addFileLimitSize will throw if `settings` is not defined', () => {
30+
const schema: DeepPartial<Schema> = {};
31+
expect(() => migration_addFileLimitSize(schema as Schema)).toThrow();
32+
});

packages/backend/src/main.test.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from 'vitest';
2-
import { isRepoReindexingRequired } from './main';
3-
import { Repository } from './types';
2+
import { isAllRepoReindexingRequired, isRepoReindexingRequired } from './main';
3+
import { Repository, Settings } from './types';
44

55
test('isRepoReindexingRequired should return false when no changes are made', () => {
66
const previous: Repository = {
@@ -77,6 +77,23 @@ test('isRepoReindexingRequired should return true when local excludedPaths chang
7777
expect(isRepoReindexingRequired(previous, current)).toBe(true);
7878
});
7979

80-
test('isAllRepoReindexingRequired ...', () => {
81-
// todo!
80+
test('isAllRepoReindexingRequired should return false when fileLimitSize has not changed', () => {
81+
const previous: Settings = {
82+
fileLimitSize: 1000,
83+
}
84+
const current: Settings = {
85+
...previous,
86+
}
87+
expect(isAllRepoReindexingRequired(previous, current)).toBe(false);
88+
});
89+
90+
test('isAllRepoReindexingRequired should return true when fileLimitSize has changed', () => {
91+
const previous: Settings = {
92+
fileLimitSize: 1000,
93+
}
94+
const current: Settings = {
95+
...previous,
96+
fileLimitSize: 2000,
97+
}
98+
expect(isAllRepoReindexingRequired(previous, current)).toBe(true);
8299
});

packages/backend/src/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,9 @@ export type AppContext = {
4444

4545
export type Settings = {
4646
fileLimitSize: number;
47-
}
47+
}
48+
49+
// @see : https://stackoverflow.com/a/61132308
50+
export type DeepPartial<T> = T extends object ? {
51+
[P in keyof T]?: DeepPartial<T[P]>;
52+
} : T;

0 commit comments

Comments
 (0)