feat: fix test

pull/2/head
crazywoola 3 years ago
parent 68176a3734
commit 55ee2d4e76

@ -1,30 +1,30 @@
import { LangGeniusClient, BASE_URL, routes } from ".."; import { DifyClient, BASE_URL, routes } from "..";
import axios from 'axios' import axios from 'axios'
jest.mock('axios') jest.mock('axios')
describe('Client', () => { describe('Client', () => {
let langGeniusClient let difyClient
beforeEach(() => { beforeEach(() => {
langGeniusClient = new LangGeniusClient('test') difyClient = new DifyClient('test')
}) })
test('should create a client', () => { test('should create a client', () => {
expect(langGeniusClient).toBeDefined(); expect(difyClient).toBeDefined();
}) })
// test updateApiKey // test updateApiKey
test('should update the api key', () => { test('should update the api key', () => {
langGeniusClient.updateApiKey('test2'); difyClient.updateApiKey('test2');
expect(langGeniusClient.apiKey).toBe('test2'); expect(difyClient.apiKey).toBe('test2');
}) })
}); });
describe('Send Requests', () => { describe('Send Requests', () => {
let langGeniusClient let difyClient
beforeEach(() => { beforeEach(() => {
langGeniusClient = new LangGeniusClient('test') difyClient = new DifyClient('test')
}) })
afterEach(() => { afterEach(() => {
@ -37,7 +37,7 @@ describe('Send Requests', () => {
const expectedResponse = { data: 'response' } const expectedResponse = { data: 'response' }
axios.mockResolvedValue(expectedResponse) axios.mockResolvedValue(expectedResponse)
await langGeniusClient.sendRequest(method, endpoint) await difyClient.sendRequest(method, endpoint)
expect(axios).toHaveBeenCalledWith({ expect(axios).toHaveBeenCalledWith({
method, method,
@ -45,7 +45,7 @@ describe('Send Requests', () => {
data: null, data: null,
params: null, params: null,
headers: { headers: {
Authorization: `Bearer ${langGeniusClient.apiKey}`, Authorization: `Bearer ${difyClient.apiKey}`,
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
responseType: 'json', responseType: 'json',
@ -59,7 +59,7 @@ describe('Send Requests', () => {
const errorMessage = 'Request failed with status code 404' const errorMessage = 'Request failed with status code 404'
axios.mockRejectedValue(new Error(errorMessage)) axios.mockRejectedValue(new Error(errorMessage))
await expect(langGeniusClient.sendRequest(method, endpoint)).rejects.toThrow( await expect(difyClient.sendRequest(method, endpoint)).rejects.toThrow(
errorMessage errorMessage
) )
}) })

Loading…
Cancel
Save