@@ -18,13 +18,6 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
1818import * as repoModule from '../../src/db/file/repo' ;
1919import { Repo } from '../../src/db/types' ;
2020
21- vi . mock ( '../../src/db/mongo/helper' , ( ) => ( {
22- connect : vi . fn ( ) ,
23- } ) ) ;
24-
25- import { connect } from '../../src/db/mongo/helper' ;
26- import * as mongoRepo from '../../src/db/mongo/repo' ;
27-
2821describe ( 'Repo dateCreated / lastModified (#1486)' , ( ) => {
2922 beforeEach ( ( ) => {
3023 vi . clearAllMocks ( ) ;
@@ -115,89 +108,4 @@ describe('Repo dateCreated / lastModified (#1486)', () => {
115108
116109 expect ( sorted . map ( ( r ) => r . name ) ) . toEqual ( [ 'stale' , 'mid' , 'fresh' ] ) ;
117110 } ) ;
118-
119- it ( 'NeDB backfillRepoDates fills missing fields without dropping other props' , async ( ) => {
120- const docs : Repo [ ] = [
121- {
122- project : 'finos' ,
123- name : 'legacy' ,
124- url : 'https://github.com/finos/legacy.git' ,
125- users : { canPush : [ 'bob' ] , canAuthorise : [ ] } ,
126- _id : 'legacy-id' ,
127- } ,
128- {
129- project : 'finos' ,
130- name : 'partial' ,
131- url : 'https://github.com/finos/partial.git' ,
132- users : { canPush : [ ] , canAuthorise : [ ] } ,
133- dateCreated : '2021-06-01T00:00:00.000Z' ,
134- _id : 'partial-id' ,
135- } ,
136- ] ;
137-
138- vi . spyOn ( repoModule . db , 'find' ) . mockImplementation ( ( _q : unknown , cb : any ) => cb ( null , docs ) ) ;
139-
140- const patches : Array < { id : string ; set : Record < string , string > } > = [ ] ;
141- vi . spyOn ( repoModule . db , 'update' ) . mockImplementation (
142- ( q : any , update : any , _o : unknown , cb : any ) => {
143- patches . push ( { id : q . _id , set : update . $set } ) ;
144- cb ( null , 1 ) ;
145- } ,
146- ) ;
147-
148- const fallback = '1970-01-01T00:00:00.000Z' ;
149- const updated = await repoModule . backfillRepoDates ( fallback ) ;
150-
151- expect ( updated ) . toBe ( 2 ) ;
152- expect ( patches ) . toEqual (
153- expect . arrayContaining ( [
154- {
155- id : 'legacy-id' ,
156- set : { dateCreated : fallback , lastModified : fallback } ,
157- } ,
158- {
159- id : 'partial-id' ,
160- set : {
161- dateCreated : '2021-06-01T00:00:00.000Z' ,
162- lastModified : '2021-06-01T00:00:00.000Z' ,
163- } ,
164- } ,
165- ] ) ,
166- ) ;
167- } ) ;
168-
169- it ( 'NeDB backfillRepoDates is a no-op when all repos already have dates' , async ( ) => {
170- vi . spyOn ( repoModule . db , 'find' ) . mockImplementation ( ( _q : unknown , cb : any ) => cb ( null , [ ] ) ) ;
171- const updateSpy = vi . spyOn ( repoModule . db , 'update' ) ;
172-
173- const updated = await repoModule . backfillRepoDates ( ) ;
174-
175- expect ( updated ) . toBe ( 0 ) ;
176- expect ( updateSpy ) . not . toHaveBeenCalled ( ) ;
177- } ) ;
178-
179- it ( 'Mongo backfillRepoDates uses updateMany with $ifNull pipeline' , async ( ) => {
180- const updateMany = vi . fn ( ) . mockResolvedValue ( { modifiedCount : 3 } ) ;
181- vi . mocked ( connect ) . mockResolvedValue ( { updateMany } as any ) ;
182-
183- const fallback = '1970-01-01T00:00:00.000Z' ;
184- const updated = await mongoRepo . backfillRepoDates ( fallback ) ;
185-
186- expect ( updated ) . toBe ( 3 ) ;
187- expect ( updateMany ) . toHaveBeenCalledWith (
188- {
189- $or : [ { dateCreated : { $exists : false } } , { lastModified : { $exists : false } } ] ,
190- } ,
191- [
192- {
193- $set : {
194- dateCreated : { $ifNull : [ '$dateCreated' , fallback ] } ,
195- lastModified : {
196- $ifNull : [ '$lastModified' , { $ifNull : [ '$dateCreated' , fallback ] } ] ,
197- } ,
198- } ,
199- } ,
200- ] ,
201- ) ;
202- } ) ;
203111} ) ;
0 commit comments