File tree 3 files changed +59
-5
lines changed
3 files changed +59
-5
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change 1
1
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' ;
4
4
5
5
test ( 'isRepoReindexingRequired should return false when no changes are made' , ( ) => {
6
6
const previous : Repository = {
@@ -77,6 +77,23 @@ test('isRepoReindexingRequired should return true when local excludedPaths chang
77
77
expect ( isRepoReindexingRequired ( previous , current ) ) . toBe ( true ) ;
78
78
} ) ;
79
79
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 ) ;
82
99
} ) ;
Original file line number Diff line number Diff line change @@ -44,4 +44,9 @@ export type AppContext = {
44
44
45
45
export type Settings = {
46
46
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 ;
You can’t perform that action at this time.
0 commit comments