@@ -75,7 +75,6 @@ describe("Use AddReferencesCommand to update data-source.ts file", () => {
75
75
76
76
expect(dataSourceResult).to.haveOwnProperty("AppDataSource");
77
77
expect(dataSourceResult.AppDataSource).to.haveOwnProperty("options");
78
- expect(dataSourceResult.AppDataSource.options).to.haveOwnProperty("entities");
79
78
80
79
${ testCode }
81
80
` ) ;
@@ -125,6 +124,8 @@ describe("Use AddReferencesCommand to update data-source.ts file", () => {
125
124
`
126
125
} ] ,
127
126
testCode : `
127
+ expect(dataSourceResult.AppDataSource.options).to.haveOwnProperty("entities");
128
+
128
129
const entities: any = dataSourceResult.AppDataSource.options.entities;
129
130
expect(entities).to.be.an("array");
130
131
expect(entities.length).to.be.gt(0);
@@ -181,6 +182,8 @@ describe("Use AddReferencesCommand to update data-source.ts file", () => {
181
182
`
182
183
} ] ,
183
184
testCode : `
185
+ expect(dataSourceResult.AppDataSource.options).to.haveOwnProperty("entities");
186
+
184
187
const entities: any = dataSourceResult.AppDataSource.options.entities;
185
188
expect(entities).to.be.an("array");
186
189
expect(entities.length).to.be.gt(0);
@@ -229,6 +232,8 @@ describe("Use AddReferencesCommand to update data-source.ts file", () => {
229
232
`
230
233
} ] ,
231
234
testCode : `
235
+ expect(dataSourceResult.AppDataSource.options).to.haveOwnProperty("entities");
236
+
232
237
const entities: any = dataSourceResult.AppDataSource.options.entities;
233
238
expect(entities).to.be.an("array");
234
239
expect(entities.length).to.be.gt(0);
@@ -277,6 +282,8 @@ describe("Use AddReferencesCommand to update data-source.ts file", () => {
277
282
`
278
283
} ] ,
279
284
testCode : `
285
+ expect(dataSourceResult.AppDataSource.options).to.haveOwnProperty("entities");
286
+
280
287
const entities: any = dataSourceResult.AppDataSource.options.entities;
281
288
expect(entities).to.be.an("array");
282
289
expect(entities.length).to.be.gt(0);
@@ -286,4 +293,100 @@ describe("Use AddReferencesCommand to update data-source.ts file", () => {
286
293
`
287
294
} ) ;
288
295
} ) ;
296
+
297
+ it ( "should add migration from folder" , async ( ) => {
298
+ await testDataSourceFile ( {
299
+ dataSourceCode : `
300
+ import { migrations } from "./migrations.js"
301
+
302
+ export const AppDataSource = new DataSource({
303
+ type: "sqlite",
304
+ database: "database.db",
305
+ migrations: migrations
306
+ });
307
+ ` ,
308
+ commandParams : {
309
+ dataSource : "data-source.ts" ,
310
+ migrations : [ "migrations" ]
311
+ } ,
312
+ files : [ {
313
+ path : "migrations.ts" ,
314
+ content : `
315
+ import { SomeMigration } from "./migrations/SomeMigration.js";
316
+
317
+ export const migrations = [
318
+ SomeMigration
319
+ ];
320
+ `
321
+ } , {
322
+ path : "migrations/SomeMigration.ts" ,
323
+ content : `
324
+ export class SomeMigration {}
325
+ `
326
+ } , {
327
+ path : "migrations/Migration2.ts" ,
328
+ content : `
329
+ export class Migration2 {}
330
+ `
331
+ } ] ,
332
+ testCode : `
333
+ expect(dataSourceResult.AppDataSource.options).to.haveOwnProperty("migrations");
334
+
335
+ const migrations: any = dataSourceResult.AppDataSource.options.migrations;
336
+ expect(migrations).to.be.an("array");
337
+ expect(migrations.length).to.be.gt(0);
338
+ const migrationNames = migrations.map((migration: any) => migration.name);
339
+ expect(migrationNames).to.include("Migration2");
340
+ expect(migrationNames).to.include("SomeMigration");
341
+ `
342
+ } ) ;
343
+ } ) ;
344
+
345
+ it ( "should add subscriber from folder" , async ( ) => {
346
+ await testDataSourceFile ( {
347
+ dataSourceCode : `
348
+ import { subscribers } from "./subscribers.js"
349
+
350
+ export const AppDataSource = new DataSource({
351
+ type: "sqlite",
352
+ database: "database.db",
353
+ subscribers: subscribers
354
+ });
355
+ ` ,
356
+ commandParams : {
357
+ dataSource : "data-source.ts" ,
358
+ subscribers : [ "subscribers" ]
359
+ } ,
360
+ files : [ {
361
+ path : "subscribers.ts" ,
362
+ content : `
363
+ import { SomeSubscriber } from "./subscribers/SomeSubscriber.js";
364
+
365
+ export const subscribers = [
366
+ SomeSubscriber
367
+ ];
368
+ `
369
+ } , {
370
+ path : "subscribers/SomeSubscriber.ts" ,
371
+ content : `
372
+ export class SomeSubscriber {}
373
+ `
374
+ } , {
375
+ path : "subscribers/Subscriber2.ts" ,
376
+ content : `
377
+ export class Subscriber2 {}
378
+ `
379
+ } ] ,
380
+ testCode : `
381
+ expect(dataSourceResult.AppDataSource.options).to.haveOwnProperty("subscribers");
382
+
383
+ const subscribers: any = dataSourceResult.AppDataSource.options.subscribers;
384
+ expect(subscribers).to.be.an("array");
385
+ expect(subscribers.length).to.be.gt(0);
386
+ const subscriberNames = subscribers.map((subscriber: any) => subscriber.name);
387
+ expect(subscriberNames).to.include("Subscriber2");
388
+ expect(subscriberNames).to.include("SomeSubscriber");
389
+ `
390
+ } ) ;
391
+ } ) ;
289
392
} ) ;
0 commit comments