|
1 | 1 | import { CollectionPartnershipType, PrismaClient } from '@prisma/client';
|
2 |
| -import { getCollectionPartnerAssociation } from './CollectionPartnerAssociation'; |
| 2 | +import { |
| 3 | + getCollectionPartnerAssociation, |
| 4 | + getCollectionPartnerAssociationForCollection, |
| 5 | +} from './CollectionPartnerAssociation'; |
3 | 6 | import {
|
4 | 7 | clear as clearDb,
|
| 8 | + createAuthorHelper, |
| 9 | + createCollectionHelper, |
5 | 10 | createCollectionPartnerAssociationHelper,
|
6 | 11 | } from '../../test/helpers';
|
7 | 12 |
|
@@ -43,4 +48,42 @@ describe('queries: CollectionPartnerAssociation', () => {
|
43 | 48 | expect(found).toBeNull();
|
44 | 49 | });
|
45 | 50 | });
|
| 51 | + |
| 52 | + describe('getCollectionPartnerAssociationForCollection', () => { |
| 53 | + it('should get an association by the externalId of the collection it references', async () => { |
| 54 | + const author = await createAuthorHelper(db, 'Any Name'); |
| 55 | + const collection = await createCollectionHelper(db, { |
| 56 | + title: 'A test collection', |
| 57 | + author, |
| 58 | + }); |
| 59 | + |
| 60 | + const association = await createCollectionPartnerAssociationHelper(db, { |
| 61 | + type: CollectionPartnershipType.PARTNERED, |
| 62 | + collection, |
| 63 | + }); |
| 64 | + |
| 65 | + const found = await getCollectionPartnerAssociationForCollection( |
| 66 | + db, |
| 67 | + collection.externalId |
| 68 | + ); |
| 69 | + |
| 70 | + expect(found).not.toBeNull(); |
| 71 | + expect(association.externalId).toEqual(found.externalId); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should fail on an invalid collection externalId', async () => { |
| 75 | + const author = await createAuthorHelper(db, 'Any Name'); |
| 76 | + const collection = await createCollectionHelper(db, { |
| 77 | + title: 'A test collection without a partnership', |
| 78 | + author, |
| 79 | + }); |
| 80 | + |
| 81 | + const found = await getCollectionPartnerAssociationForCollection( |
| 82 | + db, |
| 83 | + collection.externalId |
| 84 | + ); |
| 85 | + |
| 86 | + expect(found).toBeNull(); |
| 87 | + }); |
| 88 | + }); |
46 | 89 | });
|
0 commit comments