@@ -295,4 +295,64 @@ describe('Organization Tests', () => {
295295 expect ( updatedOrganization . partReviewGuideLink ) . toBe ( 'newlink' ) ;
296296 } ) ;
297297 } ) ;
298+
299+ describe ( 'Set Organization Platform Logo' , ( ) => {
300+ const file1 = { originalname : 'image1.png' } as Express . Multer . File ;
301+ const file2 = { originalname : 'image2.png' } as Express . Multer . File ;
302+ const file3 = { originalname : 'image3.png' } as Express . Multer . File ;
303+ it ( 'Fails if user is not an admin' , async ( ) => {
304+ await expect (
305+ OrganizationsService . setPlatformLogoImage ( file1 , await createTestUser ( wonderwomanGuest , orgId ) , organization )
306+ ) . rejects . toThrow ( new AccessDeniedAdminOnlyException ( 'update platform logo' ) ) ;
307+ } ) ;
308+
309+ it ( 'Succeeds and updates all the images' , async ( ) => {
310+ const testBatman = await createTestUser ( batmanAppAdmin , orgId ) ;
311+ ( uploadFile as Mock ) . mockImplementation ( ( file ) => {
312+ return Promise . resolve ( { name : `${ file . originalname } ` , id : `uploaded-${ file . originalname } ` } ) ;
313+ } ) ;
314+
315+ await OrganizationsService . setPlatformLogoImage ( file2 , testBatman , organization ) ;
316+
317+ const oldOrganization = await prisma . organization . findUnique ( {
318+ where : {
319+ organizationId : orgId
320+ }
321+ } ) ;
322+
323+ expect ( oldOrganization ) . not . toBeNull ( ) ;
324+ expect ( oldOrganization ?. platformLogoImageId ) . toBe ( 'uploaded-image2.png' ) ;
325+
326+ await OrganizationsService . setPlatformLogoImage ( file3 , testBatman , organization ) ;
327+
328+ const updatedOrganization = await prisma . organization . findUnique ( {
329+ where : {
330+ organizationId : orgId
331+ }
332+ } ) ;
333+
334+ expect ( updatedOrganization ?. platformLogoImageId ) . toBe ( 'uploaded-image3.png' ) ;
335+ } ) ;
336+ } ) ;
337+
338+ describe ( 'Get Organization Platform Logo' , ( ) => {
339+ it ( 'Fails if an organization does not exist' , async ( ) => {
340+ await expect ( async ( ) => await OrganizationsService . getPlatformLogoImage ( '1' ) ) . rejects . toThrow (
341+ new NotFoundException ( 'Organization' , '1' )
342+ ) ;
343+ } ) ;
344+
345+ it ( 'Succeeds and gets the image' , async ( ) => {
346+ const testBatman = await createTestUser ( batmanAppAdmin , orgId ) ;
347+ await OrganizationsService . setPlatformLogoImage (
348+ { originalname : 'image1.png' } as Express . Multer . File ,
349+ testBatman ,
350+ organization
351+ ) ;
352+ const image = await OrganizationsService . getPlatformLogoImage ( orgId ) ;
353+
354+ expect ( image ) . not . toBeNull ( ) ;
355+ expect ( image ) . toBe ( 'uploaded-image1.png' ) ;
356+ } ) ;
357+ } ) ;
298358} ) ;
0 commit comments