bcchapi 1.0.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +10 -42
  2. package/LICENSE +18 -4
  3. package/README.md +83 -91
  4. package/dist/client/client.d.ts +60 -0
  5. package/dist/client/client.d.ts.map +1 -0
  6. package/dist/client/client.js +126 -0
  7. package/dist/client/client.js.map +1 -0
  8. package/dist/client/index.d.ts +4 -0
  9. package/dist/client/index.d.ts.map +1 -0
  10. package/dist/client/index.js +3 -0
  11. package/dist/client/index.js.map +1 -0
  12. package/dist/client/types.d.ts +136 -0
  13. package/dist/client/types.d.ts.map +1 -0
  14. package/dist/client/types.js +53 -0
  15. package/dist/client/types.js.map +1 -0
  16. package/dist/index.d.ts +5 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +4 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/series/index.d.ts +2 -0
  21. package/dist/series/index.d.ts.map +1 -0
  22. package/dist/series/index.js +2 -0
  23. package/dist/series/index.js.map +1 -0
  24. package/dist/series/series.d.ts +213 -0
  25. package/dist/series/series.d.ts.map +1 -0
  26. package/dist/series/series.js +213 -0
  27. package/dist/series/series.js.map +1 -0
  28. package/dist/utils/dates.d.ts +30 -0
  29. package/dist/utils/dates.d.ts.map +1 -0
  30. package/dist/utils/dates.js +67 -0
  31. package/dist/utils/dates.js.map +1 -0
  32. package/dist/utils/index.d.ts +4 -0
  33. package/dist/utils/index.d.ts.map +1 -0
  34. package/dist/utils/index.js +4 -0
  35. package/dist/utils/index.js.map +1 -0
  36. package/dist/utils/stats.d.ts +112 -0
  37. package/dist/utils/stats.d.ts.map +1 -0
  38. package/dist/utils/stats.js +185 -0
  39. package/dist/utils/stats.js.map +1 -0
  40. package/dist/utils/transform.d.ts +79 -0
  41. package/dist/utils/transform.d.ts.map +1 -0
  42. package/dist/utils/transform.js +101 -0
  43. package/dist/utils/transform.js.map +1 -0
  44. package/package.json +62 -40
  45. package/.eslintignore +0 -3
  46. package/.eslintrc.json +0 -21
  47. package/.github/workflows/npm-publish.yml +0 -38
  48. package/.prettierrc.json +0 -17
  49. package/.vscode/extensions.json +0 -3
  50. package/.vscode/settings.json +0 -4
  51. package/src/client.ts +0 -109
  52. package/src/errors.ts +0 -36
  53. package/src/handlers.ts +0 -69
  54. package/src/index.ts +0 -8
  55. package/src/types.ts +0 -115
  56. package/src/utils.ts +0 -37
  57. package/test/client.test.ts +0 -226
  58. package/test/fixtures/index.ts +0 -15
  59. package/test/fixtures/responses/credentials.invalid.json +0 -11
  60. package/test/fixtures/responses/getseries.invalid.json +0 -11
  61. package/test/fixtures/responses/getseries.success.json +0 -87
  62. package/test/fixtures/responses/searchseries.invalid.json +0 -11
  63. package/test/fixtures/responses/searchseries.success.json +0 -22
  64. package/test/handlers/handle-get-series.test.ts +0 -45
  65. package/test/handlers/handle-search-series.test.ts +0 -48
  66. package/test/mocks/fetch.mock.ts +0 -76
  67. package/test/utils/is-valid-date.test.ts +0 -17
  68. package/test/utils/reverse-date.test.ts +0 -11
  69. package/tsconfig.eslint.json +0 -5
  70. package/tsconfig.json +0 -9
  71. package/vitest.config.mts +0 -9
@@ -1,38 +0,0 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
-
4
- name: Publish to NPM
5
-
6
- on:
7
- push:
8
- branches: main
9
-
10
- jobs:
11
- build:
12
- runs-on: ubuntu-latest
13
- permissions:
14
- contents: read
15
- steps:
16
- - uses: actions/checkout@v4
17
- - uses: actions/setup-node@v3
18
- with:
19
- node-version: 20
20
- - run: npm ci
21
- - run: npm test -- --run
22
- - run: npm run build
23
-
24
- publish-npm:
25
- needs: build
26
- runs-on: ubuntu-latest
27
- permissions:
28
- id-token: write
29
- steps:
30
- - uses: actions/checkout@v4
31
- - uses: actions/setup-node@v3
32
- with:
33
- node-version: 20
34
- registry-url: https://registry.npmjs.org/
35
- - run: npm ci
36
- - run: npm publish --provenance
37
- env:
38
- NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
package/.prettierrc.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "semi": true,
3
- "singleQuote": true,
4
- "arrowParens": "always",
5
- "trailingComma": "all",
6
- "tabWidth": 2,
7
- "printWidth": 100,
8
- "endOfLine": "lf",
9
- "overrides": [
10
- {
11
- "files": "*.json",
12
- "options": {
13
- "trailingComma": "none"
14
- }
15
- }
16
- ]
17
- }
@@ -1,3 +0,0 @@
1
- {
2
- "recommendations": ["esbenp.prettier-vscode"]
3
- }
@@ -1,4 +0,0 @@
1
- {
2
- "editor.defaultFormatter": "esbenp.prettier-vscode",
3
- "editor.formatOnSave": true
4
- }
package/src/client.ts DELETED
@@ -1,109 +0,0 @@
1
- import * as querystring from 'node:querystring';
2
- import * as assert from 'node:assert/strict';
3
- import { GetSeriesResponse, SearchSeriesResponse, ApiResponse } from './types';
4
- import { handleGetSeriesResponse, handleSearchSeriesResponse } from './handlers';
5
- import { isValidDate } from './utils';
6
-
7
- export interface ClientConfig {
8
- /**
9
- * Client username (registered email).
10
- */
11
- user: string;
12
- /**
13
- * Client password.
14
- */
15
- pass: string;
16
- }
17
-
18
- export enum Frequency {
19
- Daily = 'DAILY',
20
- Monthly = 'MONTHLY',
21
- Quarterly = 'QUARTERLY',
22
- Annual = 'ANNUAL',
23
- }
24
-
25
- export class Client {
26
- static apiURL = 'https://si3.bcentral.cl/SieteRestWS/SieteRestWS.ashx';
27
-
28
- private username: string;
29
- private password: string;
30
-
31
- constructor(config: ClientConfig) {
32
- this.username = config.user;
33
- this.password = config.pass;
34
- }
35
-
36
- async request<T extends ApiResponse>(query: Record<string, string>): Promise<T> {
37
- const queryString = querystring.stringify({
38
- user: this.username,
39
- pass: this.password,
40
- ...query,
41
- });
42
-
43
- return (await fetch(`${Client.apiURL}?${queryString}`)).json() as Promise<T>;
44
- }
45
-
46
- /**
47
- * Fetches the list of observed values for a given series.
48
- */
49
- async getSeries(params: {
50
- /**
51
- * Series identifier.
52
- */
53
- series: string;
54
- /**
55
- * First date of the range to fetch.
56
- */
57
- since?: string | Date;
58
- /**
59
- * Last date of the range to fetch.
60
- */
61
- until?: string | Date;
62
- }): Promise<GetSeriesResponse> {
63
- const { series, since, until } = params;
64
-
65
- assert.ok(series && typeof series === 'string', 'series must be a non-empty string');
66
-
67
- const query: Record<string, string> = {
68
- timeseries: series,
69
- function: 'GetSeries',
70
- };
71
-
72
- if (since) {
73
- assert.ok(isValidDate(since), '"since" is not a valid date string or Date object');
74
- query.firstdate = typeof since === 'string' ? since : since.toISOString().slice(0, 10);
75
- }
76
-
77
- if (until) {
78
- assert.ok(isValidDate(until), '"until" is not a valid date string or Date object');
79
- query.lastdate = typeof until === 'string' ? until : until.toISOString().slice(0, 10);
80
- }
81
-
82
- if (query.firstdate && query.lastdate) {
83
- assert.ok(query.firstdate <= query.lastdate, 'invalid date range');
84
- }
85
-
86
- return this.request(query).then(handleGetSeriesResponse);
87
- }
88
-
89
- /**
90
- * Fetches the list of available series by frequency and their metadata.
91
- */
92
- async searchSeries(params: {
93
- /**
94
- * Frequency for which you want to consult the catalog of available series.
95
- */
96
- frequency: Frequency;
97
- }): Promise<SearchSeriesResponse> {
98
- const { frequency } = params;
99
-
100
- assert.ok(frequency && typeof frequency === 'string', 'frequency must be a non-empty string');
101
-
102
- const query: Record<string, string> = {
103
- frequency,
104
- function: 'SearchSeries',
105
- };
106
-
107
- return this.request(query).then(handleSearchSeriesResponse);
108
- }
109
- }
package/src/errors.ts DELETED
@@ -1,36 +0,0 @@
1
- import { ErrorResponse } from './types';
2
-
3
- export enum ErrorCodes {
4
- InvalidCredentials = -5,
5
- InvalidFrequency = -1,
6
- InvalidSeries = -50,
7
- InvalidDateRange = -1,
8
- Unknown = -1,
9
- }
10
-
11
- export class WebServiceError extends Error {
12
- response?: ErrorResponse;
13
-
14
- constructor(response?: ErrorResponse, message?: string) {
15
- super(message || response?.Descripcion || 'Unknown service error');
16
- this.response = response;
17
- }
18
- }
19
-
20
- export class InvalidFrequencyError extends WebServiceError {
21
- constructor(response?: ErrorResponse) {
22
- super(response, 'Invalid frequency code (must be DAILY, MONTHLY, QUARTERLY or ANNUAL)');
23
- }
24
- }
25
-
26
- export class InvalidCredentialsError extends WebServiceError {
27
- constructor(response?: ErrorResponse) {
28
- super(response, 'Invalid username or password');
29
- }
30
- }
31
-
32
- export class InvalidSeriesError extends WebServiceError {
33
- constructor(response?: ErrorResponse) {
34
- super(response, 'Invalid series id');
35
- }
36
- }
package/src/handlers.ts DELETED
@@ -1,69 +0,0 @@
1
- import {
2
- ErrorCodes,
3
- InvalidFrequencyError,
4
- InvalidCredentialsError,
5
- InvalidSeriesError,
6
- WebServiceError,
7
- } from './errors';
8
- import {
9
- ApiResponse,
10
- SeriesObservation,
11
- SeriesMetadata,
12
- ErrorResponse,
13
- GetSeriesResponse,
14
- SearchSeriesResponse,
15
- } from './types';
16
- import { reverseDate } from './utils';
17
-
18
- /**
19
- * Parses the GetSeries function API response.
20
- */
21
- export function handleGetSeriesResponse<T extends ApiResponse>(response: T): GetSeriesResponse {
22
- if (response.Codigo !== 0) {
23
- switch (response.Codigo) {
24
- case ErrorCodes.InvalidCredentials:
25
- throw new InvalidCredentialsError(response as ApiResponse as ErrorResponse);
26
- case ErrorCodes.InvalidSeries:
27
- throw new InvalidSeriesError(response as ApiResponse as ErrorResponse);
28
- default:
29
- throw new WebServiceError(response as ApiResponse as ErrorResponse);
30
- }
31
- }
32
-
33
- return {
34
- seriesId: response.Series.seriesId || '',
35
- description: response.Series.descripIng || '',
36
- data: (response.Series.Obs || []).map((obs: SeriesObservation) => ({
37
- date: reverseDate(obs.indexDateString),
38
- value: parseFloat(obs.value),
39
- })),
40
- };
41
- }
42
-
43
- /**
44
- * Parses the SearchSeries function API response.
45
- */
46
- export function handleSearchSeriesResponse<T extends ApiResponse>(
47
- response: T,
48
- ): SearchSeriesResponse {
49
- if (response.Codigo !== 0) {
50
- switch (response.Codigo) {
51
- case ErrorCodes.InvalidCredentials:
52
- throw new InvalidCredentialsError(response as ApiResponse as ErrorResponse);
53
- case ErrorCodes.InvalidFrequency:
54
- throw new InvalidFrequencyError(response as ApiResponse as ErrorResponse);
55
- default:
56
- throw new WebServiceError(response as ApiResponse as ErrorResponse);
57
- }
58
- }
59
-
60
- return response.SeriesInfos.map((series: SeriesMetadata) => ({
61
- seriesId: series.seriesId,
62
- frequency: series.frequencyCode,
63
- title: series.englishTitle,
64
- firstObservedAt: reverseDate(series.firstObservation),
65
- lastObservedAt: reverseDate(series.lastObservation),
66
- updatedAt: reverseDate(series.updatedAt),
67
- createdAt: reverseDate(series.createdAt),
68
- }));
69
- }
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- export { Client, ClientConfig, Frequency } from './client';
2
- export { ApiResponse, ErrorResponse, GetSeriesResponse, SearchSeriesResponse } from './types';
3
- export {
4
- WebServiceError,
5
- InvalidCredentialsError,
6
- InvalidFrequencyError,
7
- InvalidSeriesError,
8
- } from './errors';
package/src/types.ts DELETED
@@ -1,115 +0,0 @@
1
- export type StatusCode = 'OK' | 'ND';
2
-
3
- export interface SeriesObservation {
4
- /**
5
- * Series observed date in DD-MM-YYYY format.
6
- */
7
- indexDateString: string;
8
- /**
9
- * Series observed value.
10
- */
11
- value: string;
12
- /**
13
- * Series observed value status code (ND = no data recorded).
14
- */
15
- statusCode: StatusCode;
16
- }
17
-
18
- export interface SeriesHistory {
19
- /**
20
- * Series identifier.
21
- */
22
- seriesId: string;
23
- /**
24
- * Series name in Spanish.
25
- */
26
- descripEsp: string;
27
- /**
28
- * Series name in English.
29
- */
30
- descripIng: string;
31
- /**
32
- * List of series observed values.
33
- */
34
- Obs: SeriesObservation[];
35
- }
36
-
37
- export type NullSeries = {
38
- [key in keyof SeriesHistory]: null;
39
- };
40
-
41
- export interface SeriesMetadata {
42
- /**
43
- * Series identifier.
44
- */
45
- seriesId: string;
46
- /**
47
- * Series frequency.
48
- */
49
- frequencyCode: string;
50
- /**
51
- * Series name in Spanish.
52
- */
53
- spanishTitle: string;
54
- /**
55
- * Series name in English.
56
- */
57
- englishTitle: string;
58
- /**
59
- * Date of first observation in DD-MM-YYYY format.
60
- */
61
- firstObservation: string;
62
- /**
63
- * Date of last observation in DD-MM-YYYY format.
64
- */
65
- lastObservation: string;
66
- /**
67
- * Date of last update in DD-MM-YYYY format.
68
- */
69
- updatedAt: string;
70
- /**
71
- * Date of creation in DD-MM-YYYY format.
72
- */
73
- createdAt: string;
74
- }
75
-
76
- export interface ApiResponse {
77
- /**
78
- * Response status code.
79
- */
80
- readonly Codigo: number;
81
- /**
82
- * Response status message.
83
- */
84
- readonly Descripcion: string;
85
-
86
- /**
87
- * Series historic information.
88
- */
89
- readonly Series: Readonly<SeriesHistory | NullSeries>;
90
- /**
91
- * Series metadata information.
92
- */
93
- readonly SeriesInfos: ReadonlyArray<SeriesMetadata>;
94
- }
95
-
96
- export interface ErrorResponse extends ApiResponse {
97
- Series: NullSeries;
98
- SeriesInfos: never[];
99
- }
100
-
101
- export interface GetSeriesResponse {
102
- seriesId: string;
103
- description: string;
104
- data: ReadonlyArray<{ date: string; value: number }>;
105
- }
106
-
107
- export type SearchSeriesResponse = ReadonlyArray<{
108
- seriesId: string;
109
- frequency: string;
110
- title: string;
111
- firstObservedAt: string;
112
- lastObservedAt: string;
113
- updatedAt: string;
114
- createdAt: string;
115
- }>;
package/src/utils.ts DELETED
@@ -1,37 +0,0 @@
1
- /**
2
- * Determines wether a given value can be parsed to a valid date.
3
- */
4
- export function isValidDate(date: unknown): boolean {
5
- if (typeof date === 'string') {
6
- // Validate format YYYY-MM-DD
7
- const isISOString = date.match(/^\d{4}-\d{2}-\d{2}$/);
8
-
9
- if (!isISOString) {
10
- return false;
11
- }
12
-
13
- // Validate parsed date timestamp
14
- const timestamp = Date.parse(date);
15
-
16
- return !Number.isNaN(timestamp);
17
- } else if (date instanceof Date) {
18
- // Validate date object
19
- return !Number.isNaN(date.getTime());
20
- }
21
- // Is invalid date
22
- return false;
23
- }
24
-
25
- /**
26
- * Reverses a date string from DD-MM-YYYY to YYYY-MM-DD format.
27
- */
28
- export function reverseDate(date: string): string {
29
- if (/^\d{4}-\d{2}-\d{2}$/.test(date)) {
30
- return date;
31
- }
32
-
33
- if (!/^\d{2}-\d{2}-\d{4}$/.test(date)) {
34
- throw new Error('Invalid date format. Expected DD-MM-YYYY');
35
- }
36
- return date.split('-').reverse().join('-');
37
- }
@@ -1,226 +0,0 @@
1
- import { expect, describe, it, vi, afterEach, beforeEach } from 'vitest';
2
- import {
3
- Client,
4
- Frequency,
5
- InvalidCredentialsError,
6
- InvalidSeriesError,
7
- InvalidFrequencyError,
8
- } from '../src';
9
- import { reverseDate } from '../src/utils';
10
- import fetchMock from './mocks/fetch.mock';
11
- import fixtures from './fixtures';
12
-
13
- const fetchSpy = vi.spyOn(global, 'fetch').mockImplementation(fetchMock);
14
-
15
- describe('Client', () => {
16
- const client = new Client({
17
- user: 'test',
18
- pass: 'test',
19
- });
20
-
21
- const invalidClient = new Client({
22
- user: '',
23
- pass: '',
24
- });
25
-
26
- it('should create a Client instance', () => {
27
- expect(client).toBeInstanceOf(Client);
28
- });
29
-
30
- describe('getSeries', () => {
31
- beforeEach(() => {
32
- fetchSpy.mockImplementation(fetchMock);
33
- });
34
- afterEach(() => {
35
- fetchSpy.mockReset();
36
- });
37
-
38
- it('should throw an error if series is not a non-empty string', async () => {
39
- await expect(
40
- client.getSeries({
41
- series: undefined as unknown as string,
42
- }),
43
- ).rejects.toThrow('series must be a non-empty string');
44
- await expect(
45
- client.getSeries({
46
- series: '',
47
- }),
48
- ).rejects.toThrow('series must be a non-empty string');
49
-
50
- expect(fetchSpy).not.toHaveBeenCalled();
51
- });
52
-
53
- it('should throw an error if date range is invalid', async () => {
54
- await expect(
55
- client.getSeries({
56
- series: 'TEST',
57
- since: 'invalid',
58
- }),
59
- ).rejects.toThrow('"since" is not a valid date string or Date object');
60
- await expect(
61
- client.getSeries({
62
- series: 'TEST',
63
- since: new Date('invalid'),
64
- }),
65
- ).rejects.toThrow('"since" is not a valid date string or Date object');
66
-
67
- await expect(
68
- client.getSeries({
69
- series: 'TEST',
70
- until: 'invalid',
71
- }),
72
- ).rejects.toThrow('"until" is not a valid date string or Date object');
73
- await expect(
74
- client.getSeries({
75
- series: 'TEST',
76
- until: new Date('invalid'),
77
- }),
78
- ).rejects.toThrow('"until" is not a valid date string or Date object');
79
-
80
- await expect(
81
- client.getSeries({
82
- series: 'TEST',
83
- since: new Date(2020, 0, 1),
84
- until: new Date(2000, 0, 1),
85
- }),
86
- ).rejects.toThrow('invalid date range');
87
-
88
- expect(fetchSpy).not.toHaveBeenCalled();
89
- });
90
-
91
- it('should throw error if credentials are invalid', async () => {
92
- await expect(invalidClient.getSeries({ series: 'TEST' })).rejects.toThrow(
93
- InvalidCredentialsError,
94
- );
95
- expect(fetchSpy).toHaveBeenCalledTimes(1);
96
- });
97
-
98
- it('should throw error if series does not exist', async () => {
99
- await expect(client.getSeries({ series: 'invalid' })).rejects.toThrow(InvalidSeriesError);
100
- expect(fetchSpy).toHaveBeenCalledTimes(1);
101
- });
102
-
103
- it('should return the series history information', async () => {
104
- const series = await client.getSeries({ series: 'TEST' });
105
-
106
- expect(fetchSpy).toHaveBeenCalledTimes(1);
107
-
108
- expect(series).toBeDefined();
109
- expect(series.seriesId).toBe('TEST');
110
- expect(series.description).toBe('Test');
111
- expect(series.data).toBeInstanceOf(Array);
112
- expect(series.data).toHaveLength(15);
113
-
114
- for (let i = 0; i < series.data.length; i += 1) {
115
- expect(series.data[i].date).toBe(
116
- reverseDate(fixtures.response.getSeriesSuccess.Series.Obs[i].indexDateString),
117
- );
118
- expect(series.data[i].value.toFixed(2)).toBe(
119
- fixtures.response.getSeriesSuccess.Series.Obs[i].value,
120
- );
121
-
122
- if (Number.isNaN(series.data[i].value)) {
123
- expect(fixtures.response.getSeriesSuccess.Series.Obs[i].statusCode).toBe('ND');
124
- }
125
- }
126
- });
127
-
128
- it('should filter the series history by date range', async () => {
129
- const series = await client.getSeries({
130
- series: 'TEST',
131
- until: '2020-12-05',
132
- });
133
-
134
- expect(fetchSpy).toHaveBeenCalledTimes(1);
135
-
136
- expect(series).toBeDefined();
137
- expect(series.seriesId).toBe('TEST');
138
- expect(series.description).toBe('Test');
139
- expect(series.data).toBeInstanceOf(Array);
140
- expect(series.data).toHaveLength(5);
141
-
142
- for (let i = 0; i < series.data.length; i += 1) {
143
- expect(series.data[i].date).toBe(
144
- reverseDate(fixtures.response.getSeriesSuccess.Series.Obs[i].indexDateString),
145
- );
146
- expect(series.data[i].value.toFixed(2)).toBe(
147
- fixtures.response.getSeriesSuccess.Series.Obs[i].value,
148
- );
149
-
150
- if (Number.isNaN(series.data[i].value)) {
151
- expect(fixtures.response.getSeriesSuccess.Series.Obs[i].statusCode).toBe('ND');
152
- }
153
- }
154
- });
155
-
156
- it('should return empty results if series has no data', async () => {
157
- const series = await client.getSeries({
158
- series: 'TEST',
159
- since: '2020-12-16',
160
- });
161
-
162
- expect(fetchSpy).toHaveBeenCalledTimes(1);
163
-
164
- expect(series).toBeDefined();
165
- expect(series.seriesId).toBe('TEST');
166
- expect(series.description).toBe('Test');
167
- expect(series.data).toBeInstanceOf(Array);
168
- expect(series.data).toHaveLength(0);
169
- });
170
- });
171
-
172
- describe('searchSeries', () => {
173
- beforeEach(() => {
174
- fetchSpy.mockImplementation(fetchMock);
175
- });
176
- afterEach(() => {
177
- fetchSpy.mockReset();
178
- });
179
-
180
- it('should throw an error if frequency is not a non-empty string', async () => {
181
- await expect(
182
- client.searchSeries({
183
- frequency: undefined as unknown as Frequency,
184
- }),
185
- ).rejects.toThrow('frequency must be a non-empty string');
186
- await expect(
187
- client.searchSeries({
188
- frequency: '' as Frequency,
189
- }),
190
- ).rejects.toThrow('frequency must be a non-empty string');
191
-
192
- expect(fetchSpy).not.toHaveBeenCalled();
193
- });
194
-
195
- it('should throw error if credentials are invalid', async () => {
196
- await expect(
197
- invalidClient.searchSeries({
198
- frequency: Frequency.Daily,
199
- }),
200
- ).rejects.toThrow(InvalidCredentialsError);
201
-
202
- expect(fetchSpy).toHaveBeenCalledTimes(1);
203
- });
204
-
205
- it('should throw error if frequency is invalid', async () => {
206
- await expect(
207
- client.searchSeries({
208
- frequency: 'invalid' as Frequency,
209
- }),
210
- ).rejects.toThrow(InvalidFrequencyError);
211
-
212
- expect(fetchSpy).toHaveBeenCalledTimes(1);
213
- });
214
-
215
- it('should return the series metadata information', async () => {
216
- const series = await client.searchSeries({
217
- frequency: Frequency.Daily,
218
- });
219
-
220
- expect(fetchSpy).toHaveBeenCalledTimes(1);
221
-
222
- expect(series).toBeInstanceOf(Array);
223
- expect(series).toHaveLength(1);
224
- });
225
- });
226
- });
@@ -1,15 +0,0 @@
1
- import getSeriesSuccess from './responses/getseries.success.json';
2
- import getSeriesInvalid from './responses/getseries.invalid.json';
3
- import searchSeriesSuccess from './responses/searchseries.success.json';
4
- import searchSeriesInvalid from './responses/searchseries.invalid.json';
5
- import credentialsInvalid from './responses/credentials.invalid.json';
6
-
7
- export default {
8
- response: {
9
- credentialsInvalid,
10
- getSeriesInvalid,
11
- getSeriesSuccess,
12
- searchSeriesInvalid,
13
- searchSeriesSuccess,
14
- },
15
- };
@@ -1,11 +0,0 @@
1
- {
2
- "Codigo": -5,
3
- "Descripcion": "Invalid username or password",
4
- "Series": {
5
- "descripEsp": null,
6
- "descripIng": null,
7
- "seriesId": null,
8
- "Obs": null
9
- },
10
- "SeriesInfos": []
11
- }