Skip to content

Commit

Permalink
fix: list pipeline template versions (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
pritamstyz4ever authored Feb 13, 2024
1 parent 0ef2d3d commit 47013bc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
16 changes: 10 additions & 6 deletions lib/pipelineTemplateVersionFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ class PipelineTemplateVersionFactory extends BaseFactory {
* @param {Object} config Config object
* @param templateMetaFactory
* @param {Datastore} config.datastore Object that will perform operations on the datastore
* @param {String} config.params.name The template name
* @param {String} config.params.namespace The template namespace
* @param {String} config.name The template name
* @param {String} config.namespace The template namespace
* @param {String} [config.params.templateId] The template id, it is mutually exclusive with name and namespace and takes precedence
* @param {String} config.sort The sort order of the list
* @param {Object} config.paginate Pagination parameters
* @param {Number} config.paginate.count Number of items per page
Expand All @@ -149,19 +150,22 @@ class PipelineTemplateVersionFactory extends BaseFactory {
config.params = {};
}

if (!config.params.name || !config.params.namespace) {
if (config.params.templateId) {
return super.list(config);
}

if (!config.name || !config.namespace) {
throw Error('name and namespace are required for pipeline template versions');
}

const pipelineTemplateMeta = await templateMetaFactory.get({
name: config.params.name,
namespace: config.params.namespace
name: config.name,
namespace: config.namespace
});

if (!pipelineTemplateMeta) {
return [];
}

config.params.templateId = pipelineTemplateMeta.id;

return super.list(config);
Expand Down
36 changes: 32 additions & 4 deletions test/lib/pipelineTemplateVersionFactory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,8 @@ describe('PipelineTemplateVersion Factory', () => {

const models = await factory.list(
{
params: {
name,
namespace
}
name,
namespace
},
templateMetaFactoryMock
);
Expand All @@ -275,6 +273,36 @@ describe('PipelineTemplateVersion Factory', () => {
namespace
});
assert.calledOnce(datastore.scan);
assert.calledWith(datastore.scan, {
table: 'pipelineTemplateVersions',
params: {
templateId
}
});
models.forEach(model => {
assert.instanceOf(model, PipelineTemplateVersion);
});
});

it('list all pipeline template versions for given templateId', async () => {
datastore.scan.resolves(returnValue);
const models = await factory.list(
{
params: {
templateId
}
},
templateMetaFactoryMock
);

assert.notCalled(templateMetaFactoryMock.get);
assert.calledOnce(datastore.scan);
assert.calledWith(datastore.scan, {
table: 'pipelineTemplateVersions',
params: {
templateId
}
});
models.forEach(model => {
assert.instanceOf(model, PipelineTemplateVersion);
});
Expand Down

0 comments on commit 47013bc

Please sign in to comment.