@@ -254,3 +254,42 @@ describe("POST /subscription/send-email/single", () => {
254254 expect ( mockSESV2Send ) . toHaveBeenCalledTimes ( 1 ) ;
255255 } ) ;
256256} ) ;
257+
258+ describe ( "GET /subscription/:mailingList" , ( ) => {
259+ it ( "should return the list of subscribers for an existing mailing list" , async ( ) => {
260+ const subscribers = [ EMAIL_1 , EMAIL_2 ] ;
261+ await SupabaseDB . SUBSCRIPTIONS . insert ( {
262+ mailingList : VALID_mailingList ,
263+ subscriptions : subscribers ,
264+ } ) ;
265+
266+ const response = await getAsAdmin (
267+ `/subscription/${ VALID_mailingList } `
268+ ) . expect ( StatusCodes . OK ) ;
269+
270+ expect ( response . body ) . toEqual ( expect . arrayContaining ( subscribers ) ) ;
271+ expect ( response . body . length ) . toBe ( 2 ) ;
272+ } ) ;
273+
274+ it ( "should return a 404 Not Found for a non-existent mailing list" , async ( ) => {
275+ const response = await getAsAdmin (
276+ "/subscription/non-existent-list"
277+ ) . expect ( StatusCodes . NOT_FOUND ) ;
278+
279+ expect ( response . body ) . toEqual ( { error : "Mailing list not found." } ) ;
280+ } ) ;
281+
282+ it ( "should return an empty array for a list that has no subscribers" , async ( ) => {
283+ // Setup: Create a list with an empty subscriptions array
284+ await SupabaseDB . SUBSCRIPTIONS . insert ( {
285+ mailingList : VALID_mailingList ,
286+ subscriptions : [ ] ,
287+ } ) ;
288+
289+ const response = await getAsAdmin (
290+ `/subscription/${ VALID_mailingList } `
291+ ) . expect ( StatusCodes . OK ) ;
292+
293+ expect ( response . body ) . toEqual ( [ ] ) ;
294+ } ) ;
295+ } ) ;
0 commit comments