mirror of
https://github.com/holidayapi/holidayapi-node.git
synced 2025-06-21 04:26:33 +00:00
feat: add workday endpoint
Added support for our latest endpoint, which calculates the workday a given number of business days into the future from the given date for the given country. Also: * perf: updated dependencies * ci: pinned eslint to 7.2.x due to airbnb incompatibility with 7.3.x. * ci: tweaked / improved eslint rules a bit. * refactor: updated types to use `;` and include weekday response. * docs: added example for new endpoint.
This commit is contained in:
parent
07988d8c71
commit
2230488d14
10 changed files with 377 additions and 177 deletions
|
@ -506,5 +506,106 @@ describe('holidayapi', () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('/v1/workday', () => {
|
||||
const basePath = `/workday?key=${key}`;
|
||||
|
||||
it('should return workday', async () => {
|
||||
const expectedResponse = {
|
||||
status: 200,
|
||||
requests: {
|
||||
used: 1000,
|
||||
available: 9000,
|
||||
resets: '2019-10-01 00:00:00',
|
||||
},
|
||||
workday: [
|
||||
{
|
||||
date: '2019-07-16',
|
||||
weekday: {
|
||||
name: 'Tuesday',
|
||||
numeric: '2',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
mockRequest.get(`${basePath}&country=US&start=2019-07-01&days=10`)
|
||||
.reply(200, expectedResponse);
|
||||
|
||||
expect(await holidayapi.workday({
|
||||
country: 'US',
|
||||
start: '2019-07-01',
|
||||
days: 10,
|
||||
})).toStrictEqual(expectedResponse);
|
||||
});
|
||||
|
||||
it('should error when country is missing', async () => {
|
||||
expect.assertions(1);
|
||||
|
||||
try {
|
||||
await holidayapi.workday();
|
||||
} catch (err) {
|
||||
expect(err.message).toMatch(/missing country/i);
|
||||
}
|
||||
});
|
||||
|
||||
it('should error when start is missing', async () => {
|
||||
expect.assertions(1);
|
||||
|
||||
try {
|
||||
await holidayapi.workday({ country: 'US' });
|
||||
} catch (err) {
|
||||
expect(err.message).toMatch(/missing start date/i);
|
||||
}
|
||||
});
|
||||
|
||||
it('should error when days is missing', async () => {
|
||||
expect.assertions(1);
|
||||
|
||||
try {
|
||||
await holidayapi.workday({ country: 'US', start: '2019-07-01' });
|
||||
} catch (err) {
|
||||
expect(err.message).toMatch(/missing days/i);
|
||||
}
|
||||
});
|
||||
|
||||
it('should error when days is negative', async () => {
|
||||
expect.assertions(1);
|
||||
|
||||
try {
|
||||
await holidayapi.workday({ country: 'US', start: '2019-07-01', days: -10 });
|
||||
} catch (err) {
|
||||
expect(err.message).toMatch(/days must be 1 or more/i);
|
||||
}
|
||||
});
|
||||
|
||||
it('should raise 4xx errors', async () => {
|
||||
const expectedResponse = {
|
||||
status: 429,
|
||||
error: 'Rate limit exceeded',
|
||||
};
|
||||
|
||||
expect.assertions(1);
|
||||
mockRequest.get(`${basePath}&country=US&start=2019-07-01&days=10`)
|
||||
.reply(429, expectedResponse);
|
||||
|
||||
try {
|
||||
await holidayapi.workday({ country: 'US', start: '2019-07-01', days: 10 });
|
||||
} catch (err) {
|
||||
expect(err.message).toMatch(/rate limit exceeded/i);
|
||||
}
|
||||
});
|
||||
|
||||
it('should raise 5xx errors', async () => {
|
||||
expect.assertions(1);
|
||||
mockRequest.get(`${basePath}&country=US&start=2019-07-01&days=10`).reply(500);
|
||||
|
||||
try {
|
||||
await holidayapi.workday({ country: 'US', start: '2019-07-01', days: 10 });
|
||||
} catch (err) {
|
||||
expect(err.message).toMatch(/internal server error/i);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue