Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
[ACS-4753] list of tags is not rendered because of missing count fiel…
Browse files Browse the repository at this point in the history
…d in backend response (#1546)

* ACS-4753 Allow to use multiple tags in where parameter

* ACS-4753 Added support for matches operator for where parameter and return to using single tag in exact searching for where parameter

* ACS-4753 Unit tests for filtered response for fetching tags

* ACS-4753 Corrected comments for function

* ACS-4753 Formatting

* ACS-4753 Fixed typo
  • Loading branch information
AleksanderSklorz committed Mar 16, 2023
1 parent b8610bb commit b4b9ffe
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 26 deletions.
9 changes: 7 additions & 2 deletions src/api/content-rest-api/api/tags.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ If not supplied then the default value is 0.
If not supplied then the default value is 100.
(default to 100)
* @param opts.fields A list of field names.
* @param opts.name Name for which tag is returned.
You can use this parameter to restrict the fields
returned within a response if, for example, you want to save on overall bandwidth.
Expand All @@ -242,6 +241,8 @@ parameter are returned in addition to those specified in the **fields** paramete
* @param opts.include Returns additional information about the tag. The following optional fields can be requested:
* count
* @param opts.tag Name or pattern for which tag is returned. Example of pattern: *test* which returns tags like 'my test 1'
* @param opts.matching Switches filtering to pattern mode instead of exact mode.
* @return Promise<TagPaging>
*/
Expand All @@ -254,12 +255,16 @@ parameter are returned in addition to those specified in the **fields** paramete

};

let where: string;
if (opts?.tag) {
where = opts.matching ? `(tag matches ('${opts.tag}'))` : `(tag='${opts.tag}')`;
}
const queryParams = {
'skipCount': opts['skipCount'],
'maxItems': opts['maxItems'],
'fields': buildCollectionParam(opts['fields'], 'csv'),
'include': buildCollectionParam(opts['include'], 'csv'),
where: opts?.name ? `(name='${opts.name}')` : undefined
where
};

const headerParams = {
Expand Down
65 changes: 50 additions & 15 deletions test/content-services/tagApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,61 @@ describe('Tags', () => {
tagsApi = new TagsApi(alfrescoJsApi);
});

it('tags', (done) => {
tagMock.get200Response();
describe('listTags', () => {
it('should load list of tags', (done) => {
tagMock.get200Response();

tagsApi.listTags().then((data) => {
expect(data.list.pagination.count).to.be.equal(2);
expect(data.list.entries[0].entry.tag).to.be.equal('tag-test-1');
expect(data.list.entries[1].entry.tag).to.be.equal('tag-test-2');
done();
tagsApi.listTags().then((data) => {
expect(data.list.pagination.count).equal(2);
expect(data.list.entries[0].entry.tag).equal('tag-test-1');
expect(data.list.entries[1].entry.tag).equal('tag-test-2');
done();
});
});

it('should handle 401 error', (done) => {
tagMock.get401Response();

tagsApi.listTags().then(
() => {},
() => {
done();
}
);
});
});

it('Tags 401', (done) => {
tagMock.get401Response();
it('should return specified tag', (done) => {
tagMock.getTagsByNamesFilterByExactTag200Response();

tagsApi.listTags().then(
() => {},
() => {
tagsApi.listTags({
tag: 'tag-test-1'
}).then((data) => {
expect(data.list.entries[0].entry).deep.equal({
tag: 'tag-test-1',
id: '0d89aa82-f2b8-4a37-9a54-f4c5148174d6'
});
done();
}
);
});
});

it('should return tags contained specified value', (done) => {
tagMock.getTagsByNameFilteredByMatching200Response();

tagsApi.listTags({
tag: '*tag-test*',
matching: true
}).then((data) => {
expect(data.list.entries[0].entry).deep.equal({
tag: 'tag-test-1',
id: '0d89aa82-f2b8-4a37-9a54-f4c5148174d6'
});
expect(data.list.entries[1].entry).deep.equal({
tag: 'tag-test-2',
id: 'd79bdbd0-9f55-45bb-9521-811e15bf48f6'
});
done();
});
});
});

describe('createTags', () => {
Expand Down
57 changes: 48 additions & 9 deletions test/mockObjects/content-services/tag.mock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import nock from 'nock';
import { BaseMock } from '../base.mock';
import { TagPaging } from '../../../src/api/content-rest-api';

export class TagMock extends BaseMock {
constructor(host?: string) {
Expand All @@ -9,22 +10,33 @@ export class TagMock extends BaseMock {
get200Response(): void {
nock(this.host, { encodedQueryParams: true })
.get('/alfresco/api/-default-/public/alfresco/versions/1/tags')
.reply(200, this.getPaginatedListOfTags());
}

getTagsByNameFilteredByMatching200Response(): void {
nock(this.host, { encodedQueryParams: true })
.get('/alfresco/api/-default-/public/alfresco/versions/1/tags?where=(tag%20matches%20(%27*tag-test*%27))')
.reply(200, this.getPaginatedListOfTags());
}

getTagsByNamesFilterByExactTag200Response(): void {
nock(this.host, { encodedQueryParams: true })
.get('/alfresco/api/-default-/public/alfresco/versions/1/tags?where=(tag%3D%27tag-test-1%27)')
.reply(200, {
list: {
pagination: { count: 2, hasMoreItems: false, skipCount: 0, maxItems: 100 },
pagination: {
count: 1,
hasMoreItems: false,
skipCount: 0,
maxItems: 100
},
entries: [
{
entry: {
tag: 'tag-test-1',
id: '0d89aa82-f2b8-4a37-9a54-f4c5148174d6',
},
},
{
entry: {
tag: 'tag-test-2',
id: 'd79bdbd0-9f55-45bb-9521-811e15bf48f6',
id: '0d89aa82-f2b8-4a37-9a54-f4c5148174d6'
},
},
}
],
},
});
Expand Down Expand Up @@ -59,4 +71,31 @@ export class TagMock extends BaseMock {
},
}]);
}

private getPaginatedListOfTags(): TagPaging {
return {
list: {
pagination: {
count: 2,
hasMoreItems: false,
skipCount: 0,
maxItems: 100
},
entries: [
{
entry: {
tag: 'tag-test-1',
id: '0d89aa82-f2b8-4a37-9a54-f4c5148174d6'
},
},
{
entry: {
tag: 'tag-test-2',
id: 'd79bdbd0-9f55-45bb-9521-811e15bf48f6'
},
},
],
},
}
}
}

0 comments on commit b4b9ffe

Please sign in to comment.