Use /tags/stats endpoint when the server supports it

This commit is contained in:
Alejandro Celaya
2023-03-18 16:26:28 +01:00
parent ddaec7c6ac
commit b87b108e53
5 changed files with 40 additions and 8 deletions

View File

@@ -202,7 +202,7 @@ describe('ShlinkApiClient', () => {
});
const { listTags } = buildApiClient();
const result = await listTags();
const result = await listTags(false);
expect({ tags: expectedTags }).toEqual(result);
expect(fetchJson).toHaveBeenCalledWith(
@@ -210,6 +210,26 @@ describe('ShlinkApiClient', () => {
expect.objectContaining({ method: 'GET' }),
);
});
it('can use /tags/stats endpoint', async () => {
const expectedTags = ['foo', 'bar'];
const expectedStats = expectedTags.map((tag) => ({ tag, shortUrlsCount: 10, visitsCount: 10 }));
fetchJson.mockResolvedValue({
tags: {
data: expectedStats,
},
});
const { listTags } = buildApiClient();
const result = await listTags(true);
expect({ tags: expectedTags, stats: expectedStats }).toEqual(result);
expect(fetchJson).toHaveBeenCalledWith(
expect.stringContaining('/tags/stats'),
expect.objectContaining({ method: 'GET' }),
);
});
});
describe('deleteTags', () => {