feat: add workdays endpoint

Added support for our new workdays endpoint that allows you to pull the
number of working days that occur between two dates.

In addition to the new endpoint:
* chore: upgraded dependencies.
* ci: dropped Node.js 10 because it past EOL.
* ci: swapped Node.js 15 for 16 now that it's out.
* docs: added example of new endpoint.
This commit is contained in:
Josh Sherman 2021-06-10 22:56:16 -05:00
parent fa2f709f82
commit bbda365fe7
7 changed files with 9755 additions and 3312 deletions

View file

@ -607,5 +607,88 @@ describe('holidayapi', () => {
}
});
});
describe('/v1/workdays', () => {
const basePath = `/workdays?key=${key}`;
it('should return workdays', async () => {
const expectedResponse = {
status: 200,
requests: {
used: 1000,
available: 9000,
resets: '2019-10-01 00:00:00',
},
workdays: 7,
};
mockRequest.get(`${basePath}&country=US&start=2019-07-01&end=2019-07-10`)
.reply(200, expectedResponse);
expect(await holidayapi.workdays({
country: 'US',
start: '2019-07-01',
end: '2019-07-10',
})).toStrictEqual(expectedResponse);
});
it('should error when country is missing', async () => {
expect.assertions(1);
try {
await holidayapi.workdays();
} catch (err) {
expect(err.message).toMatch(/missing country/i);
}
});
it('should error when start is missing', async () => {
expect.assertions(1);
try {
await holidayapi.workdays({ country: 'US' });
} catch (err) {
expect(err.message).toMatch(/missing start date/i);
}
});
it('should error when end is missing', async () => {
expect.assertions(1);
try {
await holidayapi.workdays({ country: 'US', start: '2019-07-01' });
} catch (err) {
expect(err.message).toMatch(/missing end date/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&end=2019-07-10`)
.reply(429, expectedResponse);
try {
await holidayapi.workdays({ country: 'US', start: '2019-07-01', end: '2019-07-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&end=2019-07-10`).reply(500);
try {
await holidayapi.workdays({ country: 'US', start: '2019-07-01', end: '2019-07-10' });
} catch (err) {
expect(err.message).toMatch(/internal server error/i);
}
});
});
});
});