@@ -7,7 +7,7 @@ sinon.assert.expose(assert, { prefix: '' });
7
7
8
8
describe ( 'PipelineTemplateVersion Factory' , ( ) => {
9
9
const namespace = 'namespace' ;
10
- const name = 'testPipelineTemplateVersion ' ;
10
+ const name = 'testPipelineTemplateName ' ;
11
11
const version = '1.3' ;
12
12
const tag = 'latest' ;
13
13
const metaData = {
@@ -19,7 +19,6 @@ describe('PipelineTemplateVersion Factory', () => {
19
19
let datastore ;
20
20
let factory ;
21
21
let PipelineTemplateVersion ;
22
- let PipelineTemplateMeta ;
23
22
let templateMetaFactoryMock ;
24
23
25
24
beforeEach ( ( ) => {
@@ -37,8 +36,6 @@ describe('PipelineTemplateVersion Factory', () => {
37
36
// eslint-disable-next-line global-require
38
37
PipelineTemplateVersion = require ( '../../lib/pipelineTemplateVersion' ) ;
39
38
// eslint-disable-next-line global-require
40
- PipelineTemplateMeta = require ( '../../lib/pipelineTemplate' ) ;
41
- // eslint-disable-next-line global-require
42
39
PipelineTemplateVersionFactory = require ( '../../lib/pipelineTemplateVersionFactory' ) ;
43
40
44
41
factory = new PipelineTemplateVersionFactory ( { datastore } ) ;
@@ -378,33 +375,42 @@ describe('PipelineTemplateVersion Factory', () => {
378
375
describe ( 'getWithMetadata' , async ( ) => {
379
376
const templateId = 1234135 ;
380
377
const generatedVersionId = 2341351 ;
381
- let returnValue ;
382
- const hasAllProperties = ( obj , class1 , class2 ) => {
383
- const allProps = Object . getOwnPropertyNames ( class1 . prototype ) . concat (
384
- Object . getOwnPropertyNames ( class2 . prototype )
385
- ) ;
386
-
387
- return allProps . every ( prop => prop in obj ) ;
378
+ let templateVersionMock ;
379
+
380
+ const pipelineTemplateMetaMock = {
381
+ id : templateId ,
382
+ name,
383
+ namespace,
384
+ maintainer : 'test-user@email.com' ,
385
+ pipelineId : 123 ,
386
+ latestVersion : '2.1.2' ,
387
+ trustedSinceVersion : '2.1.0'
388
388
} ;
389
389
390
+ const pipelineTemplateMetaToBeCopied = Object . keys ( pipelineTemplateMetaMock )
391
+ . filter ( key => [ 'pipelineId' , 'namespace' , 'name' , 'maintainer' , 'latestVersion' ] . includes ( key ) )
392
+ . reduce ( ( subset , key ) => {
393
+ subset [ key ] = pipelineTemplateMetaMock [ key ] ;
394
+
395
+ return subset ;
396
+ } , { } ) ;
397
+
390
398
beforeEach ( ( ) => {
391
- returnValue = {
399
+ templateVersionMock = {
392
400
id : generatedVersionId + 3 ,
393
- name,
394
401
version : '2.1.2' ,
395
- templateId
402
+ templateId,
403
+ config : { } ,
404
+ createTime : '2024-03-26T23:41:55.567Z' ,
405
+ description : 'Some description'
396
406
} ;
397
407
} ) ;
398
408
399
409
it ( 'gets a pipeline template version and meta given name, version and namespace' , async ( ) => {
400
- const pipelineTemplateMetaMock = {
401
- name,
402
- namespace,
403
- id : templateId
404
- } ;
405
-
406
410
templateMetaFactoryMock . get . resolves ( pipelineTemplateMetaMock ) ;
407
- datastore . get . resolves ( returnValue ) ;
411
+ datastore . get . resolves ( templateVersionMock ) ;
412
+
413
+ const expectedTemplateVersionWithMetadata = { ...templateVersionMock , ...pipelineTemplateMetaToBeCopied } ;
408
414
409
415
const model = await factory . getWithMetadata (
410
416
{
@@ -420,18 +426,17 @@ describe('PipelineTemplateVersion Factory', () => {
420
426
namespace
421
427
} ) ;
422
428
assert . calledOnce ( datastore . get ) ;
423
- assert . isTrue ( hasAllProperties ( model , PipelineTemplateVersion , PipelineTemplateMeta ) ) ;
429
+
430
+ assert . instanceOf ( model , PipelineTemplateVersion ) ;
431
+ Object . keys ( key => {
432
+ assert . equal ( model [ key ] , expectedTemplateVersionWithMetadata [ key ] ) ;
433
+ } ) ;
424
434
} ) ;
425
435
426
436
it ( 'gets a pipeline template version and meta given templateId' , async ( ) => {
427
- const pipelineTemplateMetaMock = {
428
- name,
429
- namespace,
430
- id : templateId
431
- } ;
432
-
433
437
templateMetaFactoryMock . get . resolves ( pipelineTemplateMetaMock ) ;
434
- datastore . get . resolves ( returnValue ) ;
438
+ datastore . get . resolves ( templateVersionMock ) ;
439
+ const expectedTemplateVersionWithMetadata = { ...pipelineTemplateMetaToBeCopied , ...templateVersionMock } ;
435
440
436
441
const model = await factory . getWithMetadata (
437
442
{
@@ -444,7 +449,10 @@ describe('PipelineTemplateVersion Factory', () => {
444
449
id : templateId
445
450
} ) ;
446
451
assert . calledOnce ( datastore . get ) ;
447
- assert . isTrue ( hasAllProperties ( model , PipelineTemplateVersion , PipelineTemplateMeta ) ) ;
452
+ assert . instanceOf ( model , PipelineTemplateVersion ) ;
453
+ Object . keys ( key => {
454
+ assert . equal ( model [ key ] , expectedTemplateVersionWithMetadata [ key ] ) ;
455
+ } ) ;
448
456
} ) ;
449
457
450
458
it ( 'Returns null if pipeline template does not exist' , async ( ) => {
@@ -462,6 +470,23 @@ describe('PipelineTemplateVersion Factory', () => {
462
470
assert . notCalled ( datastore . get ) ;
463
471
assert . isNull ( model ) ;
464
472
} ) ;
473
+
474
+ it ( 'Returns null if pipeline template version does not exist' , async ( ) => {
475
+ templateMetaFactoryMock . get . resolves ( pipelineTemplateMetaMock ) ;
476
+ datastore . get . resolves ( null ) ;
477
+
478
+ const model = await factory . get (
479
+ {
480
+ name,
481
+ namespace
482
+ } ,
483
+ templateMetaFactoryMock
484
+ ) ;
485
+
486
+ assert . calledOnce ( templateMetaFactoryMock . get ) ;
487
+ assert . calledOnce ( datastore . get ) ;
488
+ assert . isNull ( model ) ;
489
+ } ) ;
465
490
} ) ;
466
491
467
492
describe ( 'getInstance' , ( ) => {
0 commit comments