Skip to content

Commit

Permalink
test(plugin): fix plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ecyrbe committed Jan 31, 2023
1 parent f10eff5 commit aa6fedb
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 276 deletions.
2 changes: 2 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
"five-apricots-breathe",
"gentle-ligers-mix",
"good-tigers-tie",
"gorgeous-dolls-fry",
"long-fans-dress",
"lucky-brooms-fry",
"nervous-kings-bow",
"nice-kids-attend",
"nice-wombats-boil",
"polite-bugs-confess",
"polite-points-float",
"quiet-rockets-dream",
"rare-zoos-serve",
"rich-pigs-thank",
"short-hounds-mix",
Expand Down
138 changes: 0 additions & 138 deletions packages/axios/src/zodios.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,144 +165,6 @@ describe("Zodios", () => {
expect(zodios).toBeDefined();
});

it("should register have validation plugin automatically installed", () => {
const zodios = new Zodios(`http://localhost:${port}`, []);
// @ts-ignore
expect(zodios.endpointPlugins.get("any-any").count()).toBe(1);
});

it("should register a plugin", () => {
const zodios = new Zodios(`http://localhost:${port}`, []);
zodios.use({
request: async (_, config) => config,
});
// @ts-ignore
expect(zodios.endpointPlugins.get("any-any").count()).toBe(2);
});

it("should unregister a plugin", () => {
const zodios = new Zodios(`http://localhost:${port}`, []);
const id = zodios.use({
request: async (_, config) => config,
});
// @ts-ignore
expect(zodios.endpointPlugins.get("any-any").count()).toBe(2);
zodios.eject(id);
// @ts-ignore
expect(zodios.endpointPlugins.get("any-any").count()).toBe(1);
});

it("should replace a named plugin", () => {
const zodios = new Zodios(`http://localhost:${port}`, []);
const plugin: ZodiosPlugin<AnyZodiosFetcherProvider> = {
name: "test",
request: async (_, config) => config,
};
zodios.use(plugin);
zodios.use(plugin);
zodios.use(plugin);
// @ts-ignore
expect(zodios.endpointPlugins.get("any-any").count()).toBe(2);
});

it("should unregister a named plugin", () => {
const zodios = new Zodios(`http://localhost:${port}`, []);
const plugin: ZodiosPlugin<AnyZodiosFetcherProvider> = {
name: "test",
request: async (_, config) => config,
};
zodios.use(plugin);
zodios.eject("test");
// @ts-ignore
expect(zodios.endpointPlugins.get("any-any").count()).toBe(1);
});

it("should throw if invalide parameters when registering a plugin", () => {
const zodios = new Zodios(`http://localhost:${port}`, []);
// @ts-ignore
expect(() => zodios.use(0)).toThrowError("Zodios: invalid plugin");
});

it("should throw if invalid alias when registering a plugin", () => {
const zodios = new Zodios(`http://localhost:${port}`, [
{
method: "get",
path: "/:id",
alias: "test",
response: z.object({
id: z.number(),
name: z.string(),
}),
},
]);
expect(() =>
// @ts-ignore
zodios.use("tests", {
// @ts-ignore
request: async (_, config) => config,
})
).toThrowError("Zodios: no alias 'tests' found to register plugin");
});

it("should throw if invalid endpoint when registering a plugin", () => {
const zodios = new Zodios(`http://localhost:${port}`, [
{
method: "get",
path: "/:id",
response: z.object({
id: z.number(),
name: z.string(),
}),
},
]);
expect(() =>
// @ts-ignore
zodios.use("get", "/test/:id", {
// @ts-ignore
request: async (_, config) => config,
})
).toThrowError(
"Zodios: no endpoint 'get /test/:id' found to register plugin"
);
});

it("should register a plugin by endpoint", () => {
const zodios = new Zodios(`http://localhost:${port}`, [
{
method: "get",
path: "/:id",
response: z.object({
id: z.number(),
name: z.string(),
}),
},
]);
zodios.use("get", "/:id", {
request: async (_, config) => config,
});
// @ts-ignore
expect(zodios.endpointPlugins.get("get-/:id").count()).toBe(1);
});

it("should register a plugin by alias", () => {
const zodios = new Zodios(`http://localhost:${port}`, [
{
method: "get",
path: "/:id",
alias: "test",
response: z.object({
id: z.number(),
name: z.string(),
}),
},
]);
zodios.use("test", {
request: async (_, config) => config,
});
// @ts-ignore
expect(zodios.endpointPlugins.get("get-/:id").count()).toBe(1);
});

it("should make an http request", async () => {
const zodios = new Zodios(`http://localhost:${port}`, [
{
Expand Down
138 changes: 0 additions & 138 deletions packages/fetch/src/zodios.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,144 +168,6 @@ describe("Zodios", () => {
expect(zodios).toBeDefined();
});

it("should register have validation plugin automatically installed", () => {
const zodios = new Zodios(`http://localhost:${port}`, []);
// @ts-ignore
expect(zodios.endpointPlugins.get("any-any").count()).toBe(1);
});

it("should register a plugin", () => {
const zodios = new Zodios(`http://localhost:${port}`, []);
zodios.use({
request: async (_, config) => config,
});
// @ts-ignore
expect(zodios.endpointPlugins.get("any-any").count()).toBe(2);
});

it("should unregister a plugin", () => {
const zodios = new Zodios(`http://localhost:${port}`, []);
const id = zodios.use({
request: async (_, config) => config,
});
// @ts-ignore
expect(zodios.endpointPlugins.get("any-any").count()).toBe(2);
zodios.eject(id);
// @ts-ignore
expect(zodios.endpointPlugins.get("any-any").count()).toBe(1);
});

it("should replace a named plugin", () => {
const zodios = new Zodios(`http://localhost:${port}`, []);
const plugin: ZodiosPlugin<AnyZodiosFetcherProvider> = {
name: "test",
request: async (_, config) => config,
};
zodios.use(plugin);
zodios.use(plugin);
zodios.use(plugin);
// @ts-ignore
expect(zodios.endpointPlugins.get("any-any").count()).toBe(2);
});

it("should unregister a named plugin", () => {
const zodios = new Zodios(`http://localhost:${port}`, []);
const plugin: ZodiosPlugin<AnyZodiosFetcherProvider> = {
name: "test",
request: async (_, config) => config,
};
zodios.use(plugin);
zodios.eject("test");
// @ts-ignore
expect(zodios.endpointPlugins.get("any-any").count()).toBe(1);
});

it("should throw if invalide parameters when registering a plugin", () => {
const zodios = new Zodios(`http://localhost:${port}`, []);
// @ts-ignore
expect(() => zodios.use(0)).toThrowError("Zodios: invalid plugin");
});

it("should throw if invalid alias when registering a plugin", () => {
const zodios = new Zodios(`http://localhost:${port}`, [
{
method: "get",
path: "/:id",
alias: "test",
response: z.object({
id: z.number(),
name: z.string(),
}),
},
]);
expect(() =>
// @ts-ignore
zodios.use("tests", {
// @ts-ignore
request: async (_, config) => config,
})
).toThrowError("Zodios: no alias 'tests' found to register plugin");
});

it("should throw if invalid endpoint when registering a plugin", () => {
const zodios = new Zodios(`http://localhost:${port}`, [
{
method: "get",
path: "/:id",
response: z.object({
id: z.number(),
name: z.string(),
}),
},
]);
expect(() =>
// @ts-ignore
zodios.use("get", "/test/:id", {
// @ts-ignore
request: async (_, config) => config,
})
).toThrowError(
"Zodios: no endpoint 'get /test/:id' found to register plugin"
);
});

it("should register a plugin by endpoint", () => {
const zodios = new Zodios(`http://localhost:${port}`, [
{
method: "get",
path: "/:id",
response: z.object({
id: z.number(),
name: z.string(),
}),
},
]);
zodios.use("get", "/:id", {
request: async (_, config) => config,
});
// @ts-ignore
expect(zodios.endpointPlugins.get("get-/:id").count()).toBe(1);
});

it("should register a plugin by alias", () => {
const zodios = new Zodios(`http://localhost:${port}`, [
{
method: "get",
path: "/:id",
alias: "test",
response: z.object({
id: z.number(),
name: z.string(),
}),
},
]);
zodios.use("test", {
request: async (_, config) => config,
});
// @ts-ignore
expect(zodios.endpointPlugins.get("get-/:id").count()).toBe(1);
});

it("should make an http request", async () => {
const zodios = new Zodios(`http://localhost:${port}`, [
{
Expand Down

0 comments on commit aa6fedb

Please sign in to comment.