1
1
import { strictEqual } from "node:assert/strict" ;
2
2
import { describe , test } from "node:test" ;
3
3
import { fedifyHook } from "./mod.ts" ;
4
+ import type { RequestEvent } from "@sveltejs/kit" ;
4
5
5
- interface MockRequestEvent {
6
- request : Request ;
7
- }
8
-
9
- interface MockHookParams {
10
- event : MockRequestEvent ;
11
- resolve : ( event : MockRequestEvent ) => Promise < Response > ;
12
- }
13
-
14
- interface MockFederation < T > {
6
+ interface MockFederation {
15
7
fetch ( request : Request , options : unknown ) : Promise < Response > ;
16
8
}
17
9
18
10
describe ( "fedifyHook" , ( ) => {
19
11
test ( "creates hook handler function" , ( ) => {
20
- const mockFederation : MockFederation < undefined > = {
12
+ const mockFederation = {
21
13
fetch : ( ) => Promise . resolve ( new Response ( "OK" ) ) ,
22
14
} ;
23
15
24
- const createContextData = ( ) => undefined ;
25
-
26
- const hookHandler = fedifyHook ( mockFederation as never , createContextData ) ;
16
+ const hookHandler = fedifyHook ( mockFederation as never ) ;
27
17
strictEqual ( typeof hookHandler , "function" ) ;
28
18
} ) ;
29
19
30
20
test ( "calls federation.fetch with correct parameters" , async ( ) => {
31
21
let capturedRequest : Request | undefined ;
32
22
let capturedOptions : unknown ;
33
23
34
- const mockFederation : MockFederation < string > = {
24
+ const mockFederation : MockFederation = {
35
25
fetch : ( request , options ) => {
36
26
capturedRequest = request ;
37
27
capturedOptions = options ;
@@ -44,7 +34,7 @@ describe("fedifyHook", () => {
44
34
const hookHandler = fedifyHook ( mockFederation as never , createContextData ) ;
45
35
46
36
const mockRequest = new Request ( "https://example.com/test" ) ;
47
- const mockEvent : MockRequestEvent = { request : mockRequest } ;
37
+ const mockEvent : RequestEvent = { request : mockRequest } as RequestEvent ;
48
38
const mockResolve = ( ) =>
49
39
Promise . resolve ( new Response ( "SvelteKit response" ) ) ;
50
40
@@ -64,7 +54,7 @@ describe("fedifyHook", () => {
64
54
test ( "handles async context data creation" , async ( ) => {
65
55
let capturedContextData : unknown ;
66
56
67
- const mockFederation : MockFederation < string > = {
57
+ const mockFederation : MockFederation = {
68
58
fetch : ( _request , options ) => {
69
59
capturedContextData = ( options as { contextData : string } ) . contextData ;
70
60
return Promise . resolve ( new Response ( "OK" ) ) ;
@@ -79,7 +69,7 @@ describe("fedifyHook", () => {
79
69
const hookHandler = fedifyHook ( mockFederation as never , createContextData ) ;
80
70
81
71
const mockRequest = new Request ( "https://example.com/test" ) ;
82
- const mockEvent : MockRequestEvent = { request : mockRequest } ;
72
+ const mockEvent : RequestEvent = { request : mockRequest } as RequestEvent ;
83
73
const mockResolve = ( ) =>
84
74
Promise . resolve ( new Response ( "SvelteKit response" ) ) ;
85
75
0 commit comments