Skip to content

Commit

Permalink
refactor onPluginUpdate, add tests (PalisadoesFoundation#2114)
Browse files Browse the repository at this point in the history
  • Loading branch information
NamitBhutani authored Mar 28, 2024
1 parent 5052c73 commit 876beae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/resolvers/Subscription/onPluginUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export const filterFunction = async function (
): Promise<boolean> {
return true;
};

export const createPluginUpdateResponse = (payload: any): any => {
return payload.Plugin;
};
export const onPluginUpdate: SubscriptionResolvers["onPluginUpdate"] = {
// @ts-expect-error-ts-ignore
subscribe: withFilter(
(_parent, _args, context) =>
context.pubsub.asyncIterator([TALAWA_PLUGIN_UPDATED]),
(payload, _variables, context) => filterFunction(payload, context),
),
resolve: (payload: any) => {
return payload.Plugin;
},
resolve: createPluginUpdateResponse,
};
23 changes: 23 additions & 0 deletions tests/resolvers/Subscription/onPluginUpdate.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { it, describe, expect } from "vitest";
import {
filterFunction,
createPluginUpdateResponse,
} from "../../../src/resolvers/Subscription/onPluginUpdate";

describe("Subscription Resolver Tests", () => {
it("filterFunction should return true", async () => {
const payload = {};
const context = {};
const result = await filterFunction(payload, context);

expect(result).toBe(true);
});

it("createPluginUpdateResponse should return payload.Plugin", () => {
const payload = { Plugin: {} };

const result = createPluginUpdateResponse(payload);

expect(result).toBe(payload.Plugin);
});
});

0 comments on commit 876beae

Please sign in to comment.