1
1
const axios = require ( "axios" ) ;
2
- const { getOrganizations } = require ( "../controllers/eventbritecontroller" ) ;
2
+ const {
3
+ getOrganizations,
4
+ getEventById,
5
+ } = require ( "../controllers/eventbritecontroller" ) ;
3
6
4
7
jest . mock ( "axios" ) ;
5
8
6
9
describe ( "Eventbrite API" , ( ) => {
7
10
it ( "should fetch organizations from Eventbrite API" , async ( ) => {
8
-
9
11
const mockResponse = {
10
12
data : [
11
13
{
@@ -19,9 +21,8 @@ describe("Eventbrite API", () => {
19
21
] ,
20
22
} ;
21
23
22
- axios . get . mockResolvedValue ( mockResponse ) ;
24
+ axios . get . mockResolvedValue ( mockResponse ) ;
23
25
24
-
25
26
const response = await getOrganizations ( "KCIV4OKXGX3FO6FDGVYC" ) ;
26
27
27
28
expect ( axios . get ) . toHaveBeenCalledWith (
@@ -36,7 +37,43 @@ describe("Eventbrite API", () => {
36
37
expect ( response ) . toEqual ( mockResponse . data ) ;
37
38
} ) ;
38
39
40
+ it ( "should fetch a specific event from Eventbrite API" , async ( ) => {
41
+ const eventId = "688487002157" ;
42
+ const mockResponse = {
43
+ data : {
44
+ id : eventId ,
45
+ name : "Event Name" ,
46
+ description : { text : "Event description" } ,
47
+ start : { utc : "2023-07-31T15:00:00Z" } ,
48
+ end : { utc : "2023-07-31T18:00:00Z" } ,
49
+ } ,
50
+ } ;
39
51
40
- } ) ;
52
+ axios . get . mockResolvedValue ( mockResponse ) ;
41
53
54
+ const response = await getEventById ( eventId ) ;
55
+
56
+ expect ( axios . get ) . toHaveBeenCalledWith (
57
+ `https://www.eventbriteapi.com/v3/events/${ eventId } /?token=${ process . env . API_TOKEN } `
58
+ ) ;
59
+
60
+ expect ( response ) . toEqual ( mockResponse . data ) ;
61
+ } ) ;
42
62
63
+ it ( "should handle errors from Eventbrite API when fetching organizations" , async ( ) => {
64
+ axios . get . mockRejectedValue ( new Error ( "API error" ) ) ;
65
+
66
+ await expect ( getOrganizations ( "INVALID_TOKEN" ) ) . rejects . toThrow (
67
+ "Error fetching organizations from Eventbrite API"
68
+ ) ;
69
+ } ) ;
70
+
71
+ it ( "should handle errors from Eventbrite API when fetching a specific event" , async ( ) => {
72
+ const eventId = "688487002157" ;
73
+ axios . get . mockRejectedValue ( new Error ( "API error" ) ) ;
74
+
75
+ await expect ( getEventById ( eventId ) ) . rejects . toThrow (
76
+ "Error fetching event from Eventbrite API"
77
+ ) ;
78
+ } ) ;
79
+ } ) ;
0 commit comments