Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: update API code to use Axios instances#13029

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Parkreiner merged 7 commits intomainfrommes/axios-instances
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletiondocs/contributing/frontend.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -152,7 +152,7 @@ example below:
export const getAgentListeningPorts = async (
agentID: string,
): Promise<TypesGen.ListeningPortsResponse> => {
const response = awaitaxios.get(
const response = awaitaxiosInstance.get(
`/api/v2/workspaceagents/${agentID}/listening-ports`,
);
return response.data;
Expand Down
4 changes: 2 additions & 2 deletionssite/e2e/helpers.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
import { type BrowserContext, expect, type Page, test } from "@playwright/test";
import axios from "axios";
import { type ChildProcess, exec, spawn } from "child_process";
import { randomUUID } from "crypto";
import express from "express";
import capitalize from "lodash/capitalize";
import path from "path";
import * as ssh from "ssh2";
import { Duplex } from "stream";
import { axiosInstance } from "api/api";
import type {
WorkspaceBuildParameter,
UpdateTemplateMeta,
Expand DownExpand Up@@ -398,7 +398,7 @@ export const waitUntilUrlIsNotResponding = async (url: string) => {

while (retries < maxRetries) {
try {
awaitaxios.get(url);
awaitaxiosInstance.get(url);
} catch (error) {
return;
}
Expand Down
5 changes: 3 additions & 2 deletionssite/e2e/reporter.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,9 +8,9 @@ import type {
Reporter,
TestError,
} from "@playwright/test/reporter";
import axios from "axios";
import * as fs from "fs/promises";
import type { Writable } from "stream";
import { axiosInstance } from "api/api";
import { coderdPProfPort, enterpriseLicense } from "./constants";

class CoderReporter implements Reporter {
Expand DownExpand Up@@ -136,9 +136,10 @@ class CoderReporter implements Reporter {
const logLines = (chunk: string): string[] => chunk.trimEnd().split("\n");

const exportDebugPprof = async (outputFile: string) => {
const response = awaitaxios.get(
const response = awaitaxiosInstance.get(
`http://127.0.0.1:${coderdPProfPort}/debug/pprof/goroutine?debug=1`,
);

if (response.status !== 200) {
throw new Error(`Error: Received status code ${response.status}`);
}
Expand Down
22 changes: 14 additions & 8 deletionssite/src/api/api.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
import axios from "axios";
import {
MockTemplate,
MockTemplateVersionParameter1,
Expand All@@ -8,6 +7,7 @@ import {
MockWorkspaceBuildParameter1,
} from "testHelpers/entities";
import * as api from "./api";
import { axiosInstance } from "./api";
import type * as TypesGen from "./typesGenerated";

describe("api.ts", () => {
Expand All@@ -17,13 +17,16 @@ describe("api.ts", () => {
const loginResponse: TypesGen.LoginWithPasswordResponse = {
session_token: "abc_123_test",
};
jest.spyOn(axios, "post").mockResolvedValueOnce({ data: loginResponse });

jest
.spyOn(axiosInstance, "post")
.mockResolvedValueOnce({ data: loginResponse });

// when
const result = await api.login("test", "123");

// then
expect(axios.post).toHaveBeenCalled();
expect(axiosInstance.post).toHaveBeenCalled();
expect(result).toStrictEqual(loginResponse);
});

Expand All@@ -38,7 +41,7 @@ describe("api.ts", () => {
const axiosMockPost = jest.fn().mockImplementationOnce(() => {
return Promise.reject(expectedError);
});
axios.post = axiosMockPost;
axiosInstance.post = axiosMockPost;

try {
await api.login("test", "123");
Expand All@@ -54,7 +57,7 @@ describe("api.ts", () => {
const axiosMockPost = jest.fn().mockImplementationOnce(() => {
return Promise.resolve();
});
axios.post = axiosMockPost;
axiosInstance.post = axiosMockPost;

// when
await api.logout();
Expand All@@ -73,7 +76,8 @@ describe("api.ts", () => {
const axiosMockPost = jest.fn().mockImplementationOnce(() => {
return Promise.reject(expectedError);
});
axios.post = axiosMockPost;

axiosInstance.post = axiosMockPost;

try {
await api.logout();
Expand All@@ -92,7 +96,8 @@ describe("api.ts", () => {
const axiosMockPost = jest.fn().mockImplementationOnce(() => {
return Promise.resolve({ data: apiKeyResponse });
});
axios.post = axiosMockPost;

axiosInstance.post = axiosMockPost;

// when
const result = await api.getApiKey();
Expand All@@ -112,7 +117,8 @@ describe("api.ts", () => {
const axiosMockPost = jest.fn().mockImplementationOnce(() => {
return Promise.reject(expectedError);
});
axios.post = axiosMockPost;

axiosInstance.post = axiosMockPost;

try {
await api.getApiKey();
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp