Fix testing

This commit is contained in:
Arnaud 2024-09-13 19:45:59 +02:00
parent 673c899527
commit 85841b2975
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
5 changed files with 21 additions and 17 deletions

View File

@ -1,5 +1,4 @@
import assert from "assert";
import { afterEach, describe, it, vi } from "vitest";
import { afterEach, assert, describe, it, vi } from "vitest";
import { CodexDebug } from "./debug";
import type { CodexLogLevel } from "./types";

View File

@ -4,7 +4,7 @@ type ValidationError = {
expected: string;
received: string;
message: string;
path: string;
path: string | undefined;
};
/**

View File

@ -1,6 +1,6 @@
import assert from "assert";
import { afterEach, describe, it, vi } from "vitest";
import { afterEach, assert, describe, it, vi } from "vitest";
import { Fetch } from "../fetch-safe/fetch-safe";
import type { CodexError } from "../async";
class MockResponse implements Response {
headers: Headers = new Headers();
@ -81,7 +81,10 @@ describe.only("fetch", () => {
});
assert.ok(result.error);
assert.deepStrictEqual(result.data.message, "Unexpected end of JSON input");
assert.deepStrictEqual(
(result.data as CodexError).message,
"Unexpected end of JSON input"
);
});
it("returns the data when the fetch succeed", async () => {

View File

@ -1,6 +1,5 @@
import { faker } from "@faker-js/faker";
import assert from "assert";
import { afterEach, describe, it, vi } from "vitest";
import { afterEach, assert, describe, it, vi } from "vitest";
import { Fetch } from "../fetch-safe/fetch-safe";
import { CodexMarketplace } from "./marketplace";
@ -50,7 +49,7 @@ function createStorageRequest() {
function missingNumberValidationError(field: string) {
return {
error: true,
error: true as any,
data: {
message: "Cannot validate the input",
errors: [
@ -67,7 +66,7 @@ function missingNumberValidationError(field: string) {
function extraValidationError(field: string, value: unknown) {
return {
error: true,
error: true as any,
data: {
message: "Cannot validate the input",
errors: [
@ -84,7 +83,7 @@ function extraValidationError(field: string, value: unknown) {
function missingStringValidationError(field: string) {
return {
error: true,
error: true as any,
data: {
message: "Cannot validate the input",
errors: [
@ -101,7 +100,7 @@ function missingStringValidationError(field: string) {
function mistypeNumberValidationError(field: string, value: string) {
return {
error: true,
error: true as any,
data: {
message: "Cannot validate the input",
errors: [
@ -118,7 +117,7 @@ function mistypeNumberValidationError(field: string, value: string) {
function minNumberValidationError(field: string, min: number) {
return {
error: true,
error: true as any,
data: {
message: "Cannot validate the input",
errors: [
@ -140,6 +139,10 @@ function createAvailability() {
size: faker.number.int({ min: 3000, max: 300000 }),
requestId: faker.finance.ethereumAddress(),
slotIndex: faker.number.int({ min: 0, max: 9 }),
totalSize: faker.number.int({ min: 0, max: 9 }).toString(),
duration: faker.number.int({ min: 0, max: 9 }).toString(),
minPrice: faker.number.int({ min: 0, max: 9 }).toString(),
maxCollateral: faker.number.int({ min: 0, max: 9 }).toString(),
};
}
@ -242,7 +245,7 @@ describe("marketplace", () => {
});
it("returns a response when the request succeed", async () => {
const data = { ...createAvailability(), freeSize: 1000 };
const data = { ...createAvailability(), freeSize: "1000" };
const spy = vi.spyOn(Fetch, "safeJson");
spy.mockImplementationOnce(() => Promise.resolve({ error: false, data }));
@ -258,7 +261,7 @@ describe("marketplace", () => {
});
it("returns a response when the create availability succeed", async () => {
const data = { ...createAvailability(), freeSize: 1000 };
const data = { ...createAvailability(), freeSize: "1000" };
const spy = vi.spyOn(Fetch, "safeJson");
spy.mockImplementationOnce(() => Promise.resolve({ error: false, data }));

View File

@ -1,5 +1,4 @@
import assert from "assert";
import { describe, it } from "vitest";
import { assert, describe, it } from "vitest";
import { Promises } from "./promise-safe";
describe("promise safe", () => {