mirror of
https://github.com/logos-storage/logos-storage-js.git
synced 2026-01-04 14:33:07 +00:00
Fix testing
This commit is contained in:
parent
673c899527
commit
85841b2975
@ -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";
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ type ValidationError = {
|
||||
expected: string;
|
||||
received: string;
|
||||
message: string;
|
||||
path: string;
|
||||
path: string | undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -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 () => {
|
||||
|
||||
@ -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 }));
|
||||
|
||||
@ -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", () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user