Skip to content

Commit

Permalink
Add tests for redirect rules methods
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Mar 5, 2024
1 parent 3bc6240 commit 6dd43c4
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/api/ShlinkApiClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { HttpClient } from '../../src';
import { ShlinkApiClient } from '../../src';
import type {
ShlinkDomain,
ShlinkRedirectRulesList,
ShlinkSetRedirectRulesData,
ShlinkShortUrl,
ShlinkShortUrlsOrder,
ShlinkVisitsList,
Expand Down Expand Up @@ -399,4 +401,51 @@ describe('ShlinkApiClient', () => {
expect(result).toEqual(resp);
});
});

describe('getShortUrlRedirectRules', () => {
it.each([
['the_domain', '?domain=the_domain'],
[null, ''],
[undefined, ''],
])('returns the redirect rules', async (domain, expectedQuery) => {
const resp: ShlinkRedirectRulesList = {
defaultLongUrl: 'foo',
redirectRules: [],
};
jsonRequest.mockResolvedValue(resp);

const result = await apiClient.getShortUrlRedirectRules('foo', domain);

expect(jsonRequest).toHaveBeenCalledWith(
expect.stringContaining(`/short-urls/foo/redirect-rules${expectedQuery}`),
expect.objectContaining({ method: 'GET' }),
);
expect(result).toEqual(resp);
});
});

describe('setShortUrlRedirectRules', () => {
it.each([
['the_domain', '?domain=the_domain'],
[null, ''],
[undefined, ''],
])('sets redirect rules', async (domain, expectedQuery) => {
const resp: ShlinkRedirectRulesList = {
defaultLongUrl: 'foo',
redirectRules: [],
};
const data: ShlinkSetRedirectRulesData = {
redirectRules: [],
};
jsonRequest.mockResolvedValue(resp);

const result = await apiClient.setShortUrlRedirectRules('foo', domain, data);

expect(jsonRequest).toHaveBeenCalledWith(
expect.stringContaining(`/short-urls/foo/redirect-rules${expectedQuery}`),
expect.objectContaining({ method: 'POST', body: JSON.stringify(data) }),
);
expect(result).toEqual(resp);
});
});
});

0 comments on commit 6dd43c4

Please sign in to comment.