Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/plugin-hooks",
"version": "0.3.6",
"version": "0.3.5-alpha.5",
"publishConfig": {
"access": "public"
},
Expand Down Expand Up @@ -53,7 +53,6 @@
"eslint-plugin-prettier": "^5.4.0",
"graphql": "^16.6.0",
"graphql-yoga": "5.3.1",
"jest": "^29.6.4",
"prettier": "^3.5.3",
"rimraf": "5.0.1",
"typescript": "^5.8.3",
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/handleAfterAllHooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ governing permissions and limitations under the License.
*/

import getAfterAllHookHandler, { AfterAllHookBuildConfig } from '../handleAfterAllHooks';
import { PayloadContext, HookResponse, HookStatus, GraphQLResult } from '../types';
import { HookResponse, HookStatus, GraphQLResult, HookFunctionPayloadContext } from '../types';
import { mockLogger } from '../__mocks__/yogaLogger';
import { describe, expect, test, vi, beforeEach } from 'vitest';

Expand All @@ -30,7 +30,7 @@ vi.mock('../utils', async () => {

describe('getAfterAllHookHandler (afterAll)', () => {
const basePayload = {
context: {} as unknown as PayloadContext,
context: {} as unknown as HookFunctionPayloadContext,
document: {},
result: { data: { test: 'value' } },
};
Expand Down Expand Up @@ -348,7 +348,7 @@ describe('getAfterAllHookHandler (afterAll)', () => {
};
const handler = getAfterAllHookHandler(mockConfig);
const payloadWithNullResult = {
context: {} as unknown as PayloadContext,
context: {} as unknown as HookFunctionPayloadContext,
document: {},
result: null as unknown as GraphQLResult,
};
Expand All @@ -371,7 +371,7 @@ describe('getAfterAllHookHandler (afterAll)', () => {
};
const handler = getAfterAllHookHandler(mockConfig);
const payloadWithUndefinedResult = {
context: {} as unknown as PayloadContext,
context: {} as unknown as HookFunctionPayloadContext,
document: {},
result: undefined,
};
Expand Down
91 changes: 77 additions & 14 deletions src/__tests__/handleAfterSourceHooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import getAfterSourceHookHandler, { AfterSourceHookBuildConfig } from '../handle
import { HookResponse, HookStatus } from '../types';
import { mockLogger } from '../__mocks__/yogaLogger';
import { describe, expect, test, vi } from 'vitest';
import { OperationDefinitionNode } from 'graphql';

describe('getAfterSourceHookHandler', () => {
test('should return afterSourceHook function', async () => {
Expand Down Expand Up @@ -51,9 +50,13 @@ describe('getAfterSourceHookHandler', () => {
expect(mockHook).toHaveBeenCalledTimes(0);
await afterSourceHookHandler({
payload: {
context: {
request: new Request('http://localhost'),
params: {},
},
document: {},
sourceName: 'testSource',
request: { method: 'GET' },
operation: {} as OperationDefinitionNode,
response: new Response(),
setResponse: vi.fn(),
},
Expand Down Expand Up @@ -86,9 +89,13 @@ describe('getAfterSourceHookHandler', () => {
expect(mockHook).toHaveBeenCalledTimes(0);
await afterSourceHookHandler({
payload: {
context: {
request: new Request('http://localhost'),
params: {},
},
document: {},
sourceName: 'testSource',
request: { method: 'GET' },
operation: {} as OperationDefinitionNode,
response: new Response(),
setResponse: vi.fn(),
},
Expand Down Expand Up @@ -121,9 +128,15 @@ describe('getAfterSourceHookHandler', () => {
expect(mockHook).toHaveBeenCalledTimes(0);
await afterSourceHookHandler({
payload: {
context: {
request: new Request('http://localhost'),
params: {},
},
document: {},
sourceName: 'testSource',
request: { method: 'GET' },
operation: {} as OperationDefinitionNode,
response: new Response(),
setResponse: vi.fn(),
},
hookType: 'afterSource',
sourceName: 'testSource',
Expand Down Expand Up @@ -166,9 +179,15 @@ describe('getAfterSourceHookHandler', () => {
expect(mockHook2).toHaveBeenCalledTimes(0);
await afterSourceHookHandler({
payload: {
context: {
request: new Request('http://localhost'),
params: {},
},
document: {},
sourceName: 'testSource',
request: { method: 'GET' },
operation: {} as OperationDefinitionNode,
response: new Response(),
setResponse: vi.fn(),
},
hookType: 'afterSource',
sourceName: 'testSource',
Expand All @@ -188,9 +207,15 @@ describe('getAfterSourceHookHandler', () => {
await expect(
afterSourceHookHandler({
payload: {
context: {
request: new Request('http://localhost'),
params: {},
},
document: {},
sourceName: 'testSource',
request: { method: 'GET' },
operation: {} as OperationDefinitionNode,
response: new Response(),
setResponse: vi.fn(),
},
hookType: 'afterSource',
sourceName: 'testSource',
Expand All @@ -209,9 +234,15 @@ describe('getAfterSourceHookHandler', () => {
await expect(
afterSourceHookHandler({
payload: {
context: {
request: new Request('http://localhost'),
params: {},
},
document: {},
sourceName: 'testSource',
request: { method: 'GET' },
operation: {} as OperationDefinitionNode,
response: new Response(),
setResponse: vi.fn(),
},
hookType: 'afterSource',
sourceName: 'testSource',
Expand Down Expand Up @@ -243,9 +274,15 @@ describe('getAfterSourceHookHandler', () => {
await expect(
afterSourceHookHandler({
payload: {
context: {
request: new Request('http://localhost'),
params: {},
},
document: {},
sourceName: 'testSource',
request: { method: 'GET' },
operation: {} as OperationDefinitionNode,
response: new Response(),
setResponse: vi.fn(),
},
hookType: 'afterSource',
sourceName: 'testSource',
Expand Down Expand Up @@ -280,9 +317,13 @@ describe('getAfterSourceHookHandler', () => {
expect(mockMemoizedHook).toHaveBeenCalledTimes(0);
await afterSourceHookHandler({
payload: {
context: {
request: new Request('http://localhost'),
params: {},
},
document: {},
sourceName: 'testSource',
request: { method: 'GET' },
operation: {} as OperationDefinitionNode,
response: new Response(),
setResponse: vi.fn(),
},
Expand Down Expand Up @@ -313,9 +354,13 @@ describe('getAfterSourceHookHandler', () => {
await expect(
afterSourceHookHandler({
payload: {
context: {
request: new Request('http://localhost'),
params: {},
},
document: {},
sourceName: 'testSource',
request: { method: 'GET' },
operation: {} as OperationDefinitionNode,
response: new Response(),
setResponse: vi.fn(),
},
Expand Down Expand Up @@ -345,9 +390,13 @@ describe('getAfterSourceHookHandler', () => {
await expect(
afterSourceHookHandler({
payload: {
context: {
request: new Request('http://localhost'),
params: {},
},
document: {},
sourceName: 'testSource',
request: { method: 'GET' },
operation: {} as OperationDefinitionNode,
response: new Response(),
setResponse: vi.fn(),
},
Expand Down Expand Up @@ -377,9 +426,13 @@ describe('getAfterSourceHookHandler', () => {
await expect(
afterSourceHookHandler({
payload: {
context: {
request: new Request('http://localhost'),
params: {},
},
document: {},
sourceName: 'testSource',
request: { method: 'GET' },
operation: {} as OperationDefinitionNode,
response: new Response(),
setResponse: vi.fn(),
},
Expand Down Expand Up @@ -409,9 +462,13 @@ describe('getAfterSourceHookHandler', () => {
await expect(
afterSourceHookHandler({
payload: {
context: {
request: new Request('http://localhost'),
params: {},
},
document: {},
sourceName: 'testSource',
request: { method: 'GET' },
operation: {} as OperationDefinitionNode,
response: new Response(),
setResponse: vi.fn(),
},
Expand Down Expand Up @@ -442,9 +499,15 @@ describe('getAfterSourceHookHandler', () => {
};
const afterSourceHookHandler = getAfterSourceHookHandler(mockConfig);
const payload = {
context: {
request: new Request('http://localhost'),
params: {},
},
document: {},
sourceName: 'testSource',
request: { method: 'POST', body: 'test body' },
operation: { kind: 'OperationDefinition' } as OperationDefinitionNode,
response: new Response(),
setResponse: vi.fn(),
};
await afterSourceHookHandler({
payload,
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/handleBeforeAllHooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ governing permissions and limitations under the License.
*/

import getBeforeAllHookHandler, { BeforeAllHookBuildConfig } from '../handleBeforeAllHooks';
import { PayloadContext, HookResponse, HookStatus } from '../types';
import { HookFunctionPayloadContext, HookResponse, HookStatus } from '../types';
import { mockLogger } from '../__mocks__/yogaLogger';
import { describe, expect, test, vi } from 'vitest';

Expand Down Expand Up @@ -48,7 +48,7 @@ describe('getBeforeAllHookHandler', () => {
const beforeAllHookHandler = getBeforeAllHookHandler(mockConfig);
expect(mockHook).toHaveBeenCalledTimes(0);
await beforeAllHookHandler({
payload: { context: {} as unknown as PayloadContext, document: {} },
payload: { context: {} as unknown as HookFunctionPayloadContext, document: {} },
updateContext: () => {},
});
expect(mockHook).toHaveBeenCalledOnce();
Expand All @@ -73,7 +73,7 @@ describe('getBeforeAllHookHandler', () => {
const beforeAllHookHandler = getBeforeAllHookHandler(mockConfig);
expect(mockHook).toHaveBeenCalledTimes(0);
await beforeAllHookHandler({
payload: { context: {} as unknown as PayloadContext, document: {} },
payload: { context: {} as unknown as HookFunctionPayloadContext, document: {} },
updateContext: () => {},
});
expect(mockHook).toHaveBeenCalledOnce();
Expand All @@ -98,7 +98,7 @@ describe('getBeforeAllHookHandler', () => {
const beforeAllHookHandler = getBeforeAllHookHandler(mockConfig);
expect(mockHook).toHaveBeenCalledTimes(0);
await beforeAllHookHandler({
payload: { context: {} as unknown as PayloadContext, document: {} },
payload: { context: {} as unknown as HookFunctionPayloadContext, document: {} },
updateContext: () => {},
});
expect(mockHook).toHaveBeenCalledOnce();
Expand All @@ -125,7 +125,7 @@ describe('getBeforeAllHookHandler', () => {
const beforeAllHookHandler = getBeforeAllHookHandler(mockConfig);
await expect(
beforeAllHookHandler({
payload: { context: {} as unknown as PayloadContext, document: {} },
payload: { context: {} as unknown as HookFunctionPayloadContext, document: {} },
updateContext: () => {},
}),
).rejects.toThrowError(mockResponse.message);
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('getBeforeAllHookHandler', () => {
expect(mockHook).toHaveBeenCalledTimes(0);
expect(mockMemoizedHook).toHaveBeenCalledTimes(0);
await beforeAllHookHandler({
payload: { context: {} as unknown as PayloadContext, document: {} },
payload: { context: {} as unknown as HookFunctionPayloadContext, document: {} },
updateContext: () => {},
});
expect(mockHook).toHaveBeenCalledTimes(0);
Expand Down
Loading
Loading