|
1 | 1 | import { LinkCreateArgs } from 'shared'; |
2 | 2 | import OrganizationsService from '../../src/services/organizations.service'; |
3 | | -import { AccessDeniedAdminOnlyException, HttpException } from '../../src/utils/errors.utils'; |
| 3 | +import { AccessDeniedAdminOnlyException, HttpException, NotFoundException } from '../../src/utils/errors.utils'; |
4 | 4 | import { batmanAppAdmin, wonderwomanGuest } from '../test-data/users.test-data'; |
5 | 5 | import { createTestLinkType, createTestOrganization, createTestUser, resetUsers } from '../test-utils'; |
6 | 6 | import prisma from '../../src/prisma/prisma'; |
@@ -96,4 +96,36 @@ describe('Team Type Tests', () => { |
96 | 96 | expect(updatedOrganization!.usefulLinks[1].url).toBe('link 4'); |
97 | 97 | }); |
98 | 98 | }); |
| 99 | + |
| 100 | + describe('Get all Useful Links', () => { |
| 101 | + it('Fails if a organization does not exist', async () => { |
| 102 | + await expect(async () => await OrganizationsService.getAllUsefulLinks('1')).rejects.toThrow( |
| 103 | + new NotFoundException('Organization', '1') |
| 104 | + ); |
| 105 | + }); |
| 106 | + |
| 107 | + it('succeeds and gets all the links', async () => { |
| 108 | + const testLinks1: LinkCreateArgs[] = [ |
| 109 | + { |
| 110 | + linkId: '1', |
| 111 | + linkTypeName: 'Link type 1', |
| 112 | + url: 'link 1' |
| 113 | + }, |
| 114 | + { |
| 115 | + linkId: '2', |
| 116 | + linkTypeName: 'Link type 1', |
| 117 | + url: 'link 2' |
| 118 | + } |
| 119 | + ]; |
| 120 | + const testBatman = await createTestUser(batmanAppAdmin, orgId); |
| 121 | + await createTestLinkType(testBatman, orgId); |
| 122 | + await OrganizationsService.setUsefulLinks(testBatman, orgId, testLinks1); |
| 123 | + const links = await OrganizationsService.getAllUsefulLinks(orgId); |
| 124 | + |
| 125 | + expect(links).not.toBeNull(); |
| 126 | + expect(links.length).toBe(2); |
| 127 | + expect(links[0].url).toBe('link 1'); |
| 128 | + expect(links[1].url).toBe('link 2'); |
| 129 | + }); |
| 130 | + }); |
99 | 131 | }); |
0 commit comments