1+ import { describe , it , expect , vi , beforeEach , afterEach } from "vitest" ;
2+ import { NextRequest } from "next/server" ;
3+ import { GET } from "@/app/discover/route" ;
4+ import { useDiscoverParams } from "@/hooks/useDiscoverParams" ;
5+
6+ describe ( "E2E: Project Discovery Flow" , ( ) => {
7+ beforeEach ( ( ) => {
8+ // Setup for E2E tests
9+ vi . useFakeTimers ( ) ;
10+ } ) ;
11+
12+ afterEach ( ( ) => {
13+ vi . useRealTimers ( ) ;
14+ } ) ;
15+
16+ it ( "should filter projects by category" , async ( ) => {
17+ const request = new Request (
18+ "http://localhost/discover?category=design" ,
19+ {
20+ method : "GET" ,
21+ }
22+ ) ;
23+
24+ const response = await GET ( request ) ;
25+ const data = await response . json ( ) ;
26+
27+ expect ( response . status ) . toBe ( 200 ) ;
28+ expect ( data . success ) . toBe ( true ) ;
29+ if ( data . data ) {
30+ expect ( data . data . every ( ( r : any ) => r . category === "design" ) ) . toBe ( true ) ;
31+ }
32+ } ) ;
33+
34+ it ( "should filter projects by verification status" , async ( ) => {
35+ const request = new Request (
36+ "http://localhost/discover?verification=VERIFIED" ,
37+ {
38+ method : "GET" ,
39+ }
40+ ) ;
41+
42+ const response = await GET ( request ) ;
43+ const data = await response . json ( ) ;
44+
45+ expect ( response . status ) . toBe ( 200 ) ;
46+ expect ( data . success ) . toBe ( true ) ;
47+ } ) ;
48+
49+ it ( "should search projects by name or description" , async ( ) => {
50+ const request = new Request (
51+ "http://localhost/discover?search=web" ,
52+ {
53+ method : "GET" ,
54+ }
55+ ) ;
56+
57+ const response = await GET ( request ) ;
58+ const data = await response . json ( ) ;
59+
60+ expect ( response . status ) . toBe ( 200 ) ;
61+ expect ( data . success ) . toBe ( true ) ;
62+ } ) ;
63+
64+ it ( "should paginate results" , async ( ) => {
65+ const request = new Request (
66+ "http://localhost/discover?page=1&limit=9" ,
67+ {
68+ method : "GET" ,
69+ }
70+ ) ;
71+
72+ const response = await GET ( request ) ;
73+ const data = await response . json ( ) ;
74+
75+ expect ( response . status ) . toBe ( 200 ) ;
76+ expect ( data . success ) . toBe ( true ) ;
77+ if ( data . data ) {
78+ expect ( data . data . length ) . toBeLessThanOrEqual ( 9 ) ;
79+ }
80+ } ) ;
81+
82+ it ( "should sort projects by rating" , async ( ) => {
83+ const request = new Request (
84+ "http://localhost/discover?sort=rating" ,
85+ {
86+ method : "GET" ,
87+ }
88+ ) ;
89+
90+ const response = await GET ( request ) ;
91+ const data = await response . json ( ) ;
92+
93+ expect ( response . status ) . toBe ( 200 ) ;
94+ expect ( data . success ) . toBe ( true ) ;
95+ } ) ;
96+
97+ it ( "should sort projects by recently added" , async ( ) => {
98+ const request = new Request (
99+ "http://localhost/discover?sort=newest" ,
100+ {
101+ method : "GET" ,
102+ }
103+ ) ;
104+
105+ const response = await GET ( request ) ;
106+ const data = await response . json ( ) ;
107+
108+ expect ( response . status ) . toBe ( 200 ) ;
109+ expect ( data . success ) . toBe ( true ) ;
110+ } ) ;
111+
112+ it ( "should display project detail data correctly" , async ( ) => {
113+ // Test the project detail endpoint or component
114+ const request = new Request (
115+ "http://localhost/discover" ,
116+ {
117+ method : "GET" ,
118+ }
119+ ) ;
120+
121+ const response = await GET ( request ) ;
122+ const data = await response . json ( ) ;
123+
124+ expect ( response . status ) . toBe ( 200 ) ;
125+ expect ( data . success ) . toBe ( true ) ;
126+ } ) ;
127+ } ) ;
0 commit comments