Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Hold: Update Axios to latest version: 1.6.2 #338

Merged
merged 4 commits into from Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -41,23 +41,23 @@
"lint": "yarn lint:eslint:fix && yarn lint:prettier"
},
"dependencies": {
"axios": "^0.27.2",
"axios": "^1.6.2",
"ruply": "^1.0.1"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.21.0",
"@mollie/eslint-config-typescript": "^1.6.5",
"@types/jest": "24.9.0",
"@types/jest": "^29.5.11",
"@types/node": "^18.14.6",
"axios-mock-adapter": "1.19.0",
"babel-jest": "^29.5.0",
"commitizen": "^4.3.0",
"cz-conventional-changelog": "^3.3.0",
"dotenv": "^16.0.3",
"eslint": "^8.35.0",
"jest": "24.9.0",
"jest": "^29.7.0",
"jest-bluster": "^1.0.1",
"nock": "^13.3.0",
"nock-record": "^0.3.9",
Expand Down
4 changes: 2 additions & 2 deletions src/communication/NetworkClient.ts
@@ -1,7 +1,7 @@
import https from 'https';
import { type SecureContextOptions } from 'tls';

import axios, { type AxiosInstance, type AxiosRequestConfig, type AxiosRequestHeaders, type AxiosResponse } from 'axios';
import axios, { type AxiosInstance, type AxiosRequestConfig, type AxiosResponse, type RawAxiosRequestHeaders } from 'axios';

import { run } from 'ruply';
import type Page from '../data/page/Page';
Expand Down Expand Up @@ -236,7 +236,7 @@ export default class NetworkClient {

async delete<R>(pathname: string, context?: Context & IdempotencyParameter): Promise<R | true> {
// Take the idempotency key from the context, if any.
let headers: AxiosRequestHeaders | undefined = undefined;
let headers: RawAxiosRequestHeaders | undefined = undefined;
if (context?.idempotencyKey != undefined) {
const { idempotencyKey, ...rest } = context;
headers = { [idempotencyHeaderName]: idempotencyKey };
Expand Down
4 changes: 2 additions & 2 deletions src/communication/makeRetrying.ts
@@ -1,6 +1,6 @@
import { randomBytes } from 'crypto';

import axios, { type AxiosError, type AxiosInstance, type AxiosRequestConfig, type AxiosResponse, Method } from 'axios';
import axios, { type InternalAxiosRequestConfig, type AxiosRequestConfig, type AxiosError, type AxiosInstance, type AxiosResponse, type Method } from 'axios';

/**
* The name of the property in the request configuration which indicates which attempt this is. `0` for the initial
Expand Down Expand Up @@ -97,7 +97,7 @@ export default function makeRetrying(axiosInstance: AxiosInstance) {
}
// Set the attempt (in the request configuration).
config[attemptIndex] = (config[attemptIndex] ?? -1) + 1;
return config;
return config as InternalAxiosRequestConfig;
});
// Intercept any erroneous responses, and consider doing another attempt.
axiosInstance.interceptors.response.use(undefined, error => {
Expand Down
5 changes: 3 additions & 2 deletions tests/communication/custom-idempotency-key.test.ts
Expand Up @@ -89,13 +89,14 @@ describe('custom-idempotency-key', () => {
);

// Expect the first network request to have been made, and the promise to be pending.
await tick();
await jest.advanceTimersByTimeAsync(0); // process request
expect(errorInterceptor).toBeDepleted();
expect(paymentPromise).toBePending();

// Expect the second network request to have been made after two seconds, proving the Idempotency-Key header was
// consistent across these two network requests, and the promise to have fulfilled.
jest.advanceTimersByTime(2e3);
await tick();
await jest.advanceTimersByTimeAsync(3e3);
await tick();
expect(successInterceptor).toBeDepleted();
expect(paymentPromise).toBeFulfilledWith(expect.objectContaining({ id: 'tr_WDqYK6vllg' }));
Expand Down
26 changes: 16 additions & 10 deletions tests/communication/request-retrying.test.ts
Expand Up @@ -104,13 +104,14 @@ describe('request-retrying', () => {
const paymentPromise = observePromise(mollieClient.payments.get('tr_WDqYK6vllg'));

// Expect the first network request to have been made, and the promise to be pending.
await tick();
await jest.advanceTimersByTimeAsync(0); // process request
expect(errorInterceptor).toBeDepleted();
expect(successInterceptor).not.toBeDepleted();
expect(paymentPromise).toBePending();

// Expect the second network request to have been made after two seconds, and the promise to have fulfilled.
jest.advanceTimersByTime(2e3);
await tick();
await jest.advanceTimersByTimeAsync(2e3);
await tick();
expect(successInterceptor).toBeDepleted();
expect(paymentPromise).toBeFulfilledWith(expect.objectContaining({ id: 'tr_WDqYK6vllg' }));
Expand Down Expand Up @@ -143,20 +144,22 @@ describe('request-retrying', () => {
const paymentPromise = observePromise(mollieClient.payments.get('tr_WDqYK6vllg'));

// Expect a timeout to have been scheduled for the next attempt, and the promise to be pending.
await tick();
await jest.advanceTimersByTimeAsync(0); // process request
expect(interceptor).not.toBeDepleted();
expect(paymentPromise).toBePending();

// After two seconds: expect another timeout to have been scheduled for the next attempt, and the promise to still
// be pending.
jest.advanceTimersByTime(2e3);
await tick();
await jest.advanceTimersByTimeAsync(2e3);
await tick();
expect(interceptor).not.toBeDepleted();
expect(paymentPromise).toBePending();

// After another two seconds: expect three network requests to have been made in total, and the promise to be
// rejected.
jest.advanceTimersByTime(2e3);
await tick();
await jest.advanceTimersByTimeAsync(2e3);
await tick();
expect(interceptor).toBeDepleted();
expect(paymentPromise).toBeRejectedWith(expect.objectContaining({ message: 'Mock error' }));
Expand All @@ -181,21 +184,23 @@ describe('request-retrying', () => {
const paymentPromise = observePromise(mollieClient.payments.get('tr_WDqYK6vllg'));

// Expect the first network request to have been made, and the promise to be pending.
await tick();
await jest.advanceTimersByTimeAsync(0); // process request
expect(errorInterceptor).toBeDepleted();
expect(successInterceptor).not.toBeDepleted();
expect(paymentPromise).toBePending();

// Expect the client to respect the five-second Retry-After header, and thus nothing having changed after two
// seconds.
jest.advanceTimersByTime(2e3);
await tick();
await jest.advanceTimersByTimeAsync(2e3);
await tick();
expect(errorInterceptor).toBeDepleted();
expect(successInterceptor).not.toBeDepleted();
expect(paymentPromise).toBePending();

// Expect the second network request to have been made after two seconds, and the promise to have fulfilled.
jest.advanceTimersByTime(3e3);
await tick();
await jest.advanceTimersByTimeAsync(3e3);
await tick();
expect(successInterceptor).toBeDepleted();
expect(paymentPromise).toBeFulfilledWith(expect.objectContaining({ id: 'tr_WDqYK6vllg' }));
Expand Down Expand Up @@ -245,7 +250,7 @@ describe('request-retrying', () => {
);

// Expect the first network request to have been made, and the promise to be pending.
await tick();
await jest.advanceTimersByTimeAsync(0); // process request
expect(errorInterceptor).toBeDepleted();
expect(paymentPromise).toBePending();

Expand All @@ -255,7 +260,8 @@ describe('request-retrying', () => {

// Expect the second network request to have been made after two seconds, proving the Idempotency-Key header was
// consistent across these two network requests, and the promise to have fulfilled.
jest.advanceTimersByTime(2e3);
await tick();
await jest.advanceTimersByTimeAsync(2e3);
await tick();
expect(successInterceptor).toBeDepleted();
expect(paymentPromise).toBeFulfilledWith(expect.objectContaining({ id: 'tr_WDqYK6vllg' }));
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/chargebacks.test.ts
@@ -1,12 +1,11 @@
import axios from 'axios';
import httpAdapter from 'axios/lib/adapters/http';
import dotenv from 'dotenv';
import createMollieClient from '../..';

/**
* Overwrite the default XMLHttpRequestAdapter
*/
axios.defaults.adapter = httpAdapter;
axios.defaults.adapter = 'http';

/**
* Load the API_KEY environment variable
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/customers.test.ts
@@ -1,12 +1,11 @@
import axios from 'axios';
import httpAdapter from 'axios/lib/adapters/http';
import dotenv from 'dotenv';
import createMollieClient from '../..';

/**
* Overwrite the default XMLHttpRequestAdapter
*/
axios.defaults.adapter = httpAdapter;
axios.defaults.adapter = 'http';

/**
* Load the API_KEY environment variable
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/methods.test.ts
@@ -1,12 +1,11 @@
import axios from 'axios';
import httpAdapter from 'axios/lib/adapters/http';
import dotenv from 'dotenv';
import createMollieClient from '../..';

/**
* Overwrite the default XMLHttpRequestAdapter
*/
axios.defaults.adapter = httpAdapter;
axios.defaults.adapter = 'http';

/**
* Load the API_KEY environment variable
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/orders.test.ts
@@ -1,12 +1,13 @@
import axios from 'axios';
import httpAdapter from 'axios/lib/adapters/http';
import dotenv from 'dotenv';
import createMollieClient, { PaymentMethod, OrderLineType, Locale, OrderEmbed, Payment } from '../..';
import { fail } from 'node:assert';

import createMollieClient, { Locale, OrderEmbed, OrderLineType, Payment, PaymentMethod } from '../..';

/**
* Overwrite the default XMLHttpRequestAdapter
*/
axios.defaults.adapter = httpAdapter;
axios.defaults.adapter = 'http';

/**
* Load the API_KEY environment variable
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/payments.test.ts
@@ -1,12 +1,13 @@
import axios from 'axios';
import httpAdapter from 'axios/lib/adapters/http';
import dotenv from 'dotenv';
import { fail } from 'node:assert';

import createMollieClient from '../..';

/**
* Overwrite the default XMLHttpRequestAdapter
*/
axios.defaults.adapter = httpAdapter;
axios.defaults.adapter = 'http';

/**
* Load the API_KEY environment variable
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/refunds.test.ts
@@ -1,12 +1,11 @@
import axios from 'axios';
import httpAdapter from 'axios/lib/adapters/http';
import dotenv from 'dotenv';
import createMollieClient from '../..';

/**
* Overwrite the default XMLHttpRequestAdapter
*/
axios.defaults.adapter = httpAdapter;
axios.defaults.adapter = 'http';

/**
* Load the API_KEY environment variable
Expand Down
12 changes: 8 additions & 4 deletions tests/iteration/multipage-iteration.test.ts
Expand Up @@ -63,7 +63,7 @@ describe('multipage-iteration', () => {

test('throttling', async () => {
const { interceptor: firstInterceptor, intercept: interceptNext } = intercept(128);
const { interceptor: secondIntercetptor } = interceptNext(128);
const { interceptor: secondInterceptor } = interceptNext(128);

jest.useFakeTimers();

Expand All @@ -79,17 +79,21 @@ describe('multipage-iteration', () => {
);

// Expect the first network request to have been made, and the count to be 128.
await jest.advanceTimersByTimeAsync(0); // process request
await tick();
expect(firstInterceptor).toBeDepleted();
expect(secondIntercetptor).not.toBeDepleted();
expect(secondInterceptor).not.toBeDepleted();
expect(count).toBe(128);

// Expect the second network request to have been made after six seconds, and the count to be 200.
jest.advanceTimersByTime(6e3);
await tick();
expect(secondIntercetptor).toBeDepleted();
await jest.advanceTimersByTimeAsync(6e3);
await tick();
expect(secondInterceptor).toBeDepleted();
expect(count).toBe(200);
expect(promise).toBeFulfilledWith(undefined);

jest.useRealTimers();
});

afterAll(() => networkMocker.cleanup());
Expand Down