mirror of
https://github.com/holidayapi/holidayapi-node.git
synced 2025-06-21 04:26:33 +00:00
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:
parent
fa2f709f82
commit
bbda365fe7
7 changed files with 9755 additions and 3312 deletions
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
|
@ -6,7 +6,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: ['10', '12', '14', '15']
|
node-version: ['12', '14', '16']
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
@ -25,7 +25,7 @@ jobs:
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: npm run test:coverage
|
run: npm run test:coverage
|
||||||
- name: Upload Coverage
|
- name: Upload Coverage
|
||||||
if: ${{ matrix.node-version == '15' }}
|
if: ${{ matrix.node-version == '16' }}
|
||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v1
|
||||||
with:
|
with:
|
||||||
file: ./coverage/lcov.info
|
file: ./coverage/lcov.info
|
||||||
|
|
12
README.md
12
README.md
|
@ -251,3 +251,15 @@ holidayApi.workday({
|
||||||
days: 7,
|
days: 7,
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Workdays
|
||||||
|
|
||||||
|
#### Fetch number of workdays between two dates
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
holidayApi.workday({
|
||||||
|
country: 'US',
|
||||||
|
start: '2019-07-01',
|
||||||
|
end: '2019-07-10',
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
12928
package-lock.json
generated
12928
package-lock.json
generated
File diff suppressed because it is too large
Load diff
10
package.json
10
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "holidayapi",
|
"name": "holidayapi",
|
||||||
"version": "4.2.0",
|
"version": "5.0.0",
|
||||||
"description": "Official Node.js library for Holiday API",
|
"description": "Official Node.js library for Holiday API",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
@ -21,12 +21,12 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://holidayapi.com",
|
"homepage": "https://holidayapi.com",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 10.0.0"
|
"node": ">= 12.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^26.0.19",
|
"@types/jest": "^26.0.19",
|
||||||
"@types/nock": "^11.1.0",
|
"@types/nock": "^11.1.0",
|
||||||
"@types/node": "^14.14.16",
|
"@types/node": "^15.12.2",
|
||||||
"@types/node-fetch": "^2.5.7",
|
"@types/node-fetch": "^2.5.7",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.11.1",
|
"@typescript-eslint/eslint-plugin": "^4.11.1",
|
||||||
"@typescript-eslint/parser": "^4.11.1",
|
"@typescript-eslint/parser": "^4.11.1",
|
||||||
|
@ -34,9 +34,9 @@
|
||||||
"eslint-config-airbnb-base": "^14.2.1",
|
"eslint-config-airbnb-base": "^14.2.1",
|
||||||
"eslint-plugin-import": "^2.22.1",
|
"eslint-plugin-import": "^2.22.1",
|
||||||
"eslint-plugin-jest": "^24.1.3",
|
"eslint-plugin-jest": "^24.1.3",
|
||||||
"jest": "^26.6.3",
|
"jest": "^27.0.4",
|
||||||
"nock": "^13.0.5",
|
"nock": "^13.0.5",
|
||||||
"ts-jest": "^26.4.4",
|
"ts-jest": "^27.0.3",
|
||||||
"typescript": "^4.1.3"
|
"typescript": "^4.1.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -19,6 +19,8 @@ import {
|
||||||
Responses,
|
Responses,
|
||||||
WorkdayRequest,
|
WorkdayRequest,
|
||||||
WorkdayResponse,
|
WorkdayResponse,
|
||||||
|
WorkdaysRequest,
|
||||||
|
WorkdaysResponse,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
export class HolidayAPI {
|
export class HolidayAPI {
|
||||||
|
@ -102,4 +104,16 @@ export class HolidayAPI {
|
||||||
|
|
||||||
return this.request('workday', request);
|
return this.request('workday', request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async workdays(request: WorkdaysRequest = {}): Promise<WorkdaysResponse> {
|
||||||
|
if (!request.country) {
|
||||||
|
throw new Error('Missing country');
|
||||||
|
} else if (!request.start) {
|
||||||
|
throw new Error('Missing start date');
|
||||||
|
} else if (!request.end) {
|
||||||
|
throw new Error('Missing end date');
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.request('workdays', request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
16
src/types.ts
16
src/types.ts
|
@ -1,11 +1,11 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Gravity Boulevard; LLC
|
* Copyright (c) Gravity Boulevard, LLC
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
* This source code is licensed under the MIT license found in the
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type Endpoint = 'countries' | 'holidays' | 'languages' | 'workday';
|
export type Endpoint = 'countries' | 'holidays' | 'languages' | 'workday' | 'workdays';
|
||||||
|
|
||||||
type Weekday = {
|
type Weekday = {
|
||||||
name: 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday' | 'Sunday';
|
name: 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday' | 'Sunday';
|
||||||
|
@ -46,6 +46,12 @@ export type WorkdayRequest = Request & {
|
||||||
days?: number;
|
days?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type WorkdaysRequest = Request & {
|
||||||
|
country?: string;
|
||||||
|
start?: string;
|
||||||
|
end?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type Response = {
|
export type Response = {
|
||||||
requests: {
|
requests: {
|
||||||
available: number;
|
available: number;
|
||||||
|
@ -105,11 +111,16 @@ export type WorkdayResponse = Response & {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type WorkdaysResponse = Response & {
|
||||||
|
workdays?: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type Requests = (
|
export type Requests = (
|
||||||
| CountriesRequest
|
| CountriesRequest
|
||||||
| HolidaysRequest
|
| HolidaysRequest
|
||||||
| LanguagesRequest
|
| LanguagesRequest
|
||||||
| WorkdayRequest
|
| WorkdayRequest
|
||||||
|
| WorkdaysRequest
|
||||||
);
|
);
|
||||||
|
|
||||||
export type Responses = (
|
export type Responses = (
|
||||||
|
@ -117,4 +128,5 @@ export type Responses = (
|
||||||
| HolidaysResponse
|
| HolidaysResponse
|
||||||
| LanguagesResponse
|
| LanguagesResponse
|
||||||
| WorkdayResponse
|
| WorkdayResponse
|
||||||
|
| WorkdaysResponse
|
||||||
);
|
);
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue