Skip to content

Commit 09f1158

Browse files
committed
Added: formatting
1 parent 513b312 commit 09f1158

File tree

2 files changed

+62
-52
lines changed

2 files changed

+62
-52
lines changed

src/collections/infra/repositories/CollectionsRepository.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ export class CollectionsRepository extends ApiRepository implements ICollections
6767
collectionDTO: CollectionDTO,
6868
parentCollectionId: number | string = ROOT_COLLECTION_ALIAS
6969
): Promise<number> {
70-
const requestBody = this.createCreateOrUpdateRequestBody(collectionDTO);
70+
const requestBody = this.createCreateOrUpdateRequestBody(collectionDTO)
7171

7272
return this.doPost(`/${this.collectionsResourceName}/${parentCollectionId}`, requestBody)
7373
.then((response) => response.data.data.id)
7474
.catch((error) => {
75-
throw error;
76-
});
75+
throw error
76+
})
7777
}
7878

7979
public async getCollectionFacets(
@@ -160,26 +160,30 @@ export class CollectionsRepository extends ApiRepository implements ICollections
160160
collectionIdOrAlias: string | number,
161161
updatedCollection: CollectionDTO
162162
): Promise<void> {
163-
const requestBody = this.createCreateOrUpdateRequestBody(updatedCollection);
163+
const requestBody = this.createCreateOrUpdateRequestBody(updatedCollection)
164164

165165
return this.doPut(`/${this.collectionsResourceName}/${collectionIdOrAlias}`, requestBody)
166166
.then(() => undefined)
167167
.catch((error) => {
168-
throw error;
169-
});
168+
throw error
169+
})
170170
}
171171

172-
private createCreateOrUpdateRequestBody(collectionDTO: CollectionDTO): NewCollectionRequestPayload {
173-
const dataverseContacts: NewCollectionContactRequestPayload[] = collectionDTO.contacts.map((contact) => ({
174-
contactEmail: contact
175-
}));
172+
private createCreateOrUpdateRequestBody(
173+
collectionDTO: CollectionDTO
174+
): NewCollectionRequestPayload {
175+
const dataverseContacts: NewCollectionContactRequestPayload[] = collectionDTO.contacts.map(
176+
(contact) => ({
177+
contactEmail: contact
178+
})
179+
)
176180

177181
const inputLevelsRequestBody: NewCollectionInputLevelRequestPayload[] =
178182
collectionDTO.inputLevels?.map((inputLevel) => ({
179183
datasetFieldTypeName: inputLevel.datasetFieldName,
180184
include: inputLevel.include,
181185
required: inputLevel.required
182-
}));
186+
}))
183187

184188
return {
185189
alias: collectionDTO.alias,
@@ -193,7 +197,7 @@ export class CollectionsRepository extends ApiRepository implements ICollections
193197
facetIds: collectionDTO.facetIds,
194198
inputLevels: inputLevelsRequestBody
195199
}
196-
};
200+
}
197201
}
198202

199203
private applyCollectionSearchCriteriaToQueryParams(
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,54 @@
1-
import { ApiConfig, WriteError, createCollection, getCollection, updateCollection } from '../../../src'
1+
import {
2+
ApiConfig,
3+
WriteError,
4+
createCollection,
5+
getCollection,
6+
updateCollection
7+
} from '../../../src'
28
import { TestConstants } from '../../testHelpers/TestConstants'
39
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
410
import { createCollectionDTO } from '../../testHelpers/collections/collectionHelper'
511

612
describe('execute', () => {
7-
beforeEach(async () => {
8-
ApiConfig.init(
9-
TestConstants.TEST_API_URL,
10-
DataverseApiAuthMechanism.API_KEY,
11-
process.env.TEST_API_KEY
12-
)
13-
})
13+
beforeEach(async () => {
14+
ApiConfig.init(
15+
TestConstants.TEST_API_URL,
16+
DataverseApiAuthMechanism.API_KEY,
17+
process.env.TEST_API_KEY
18+
)
19+
})
1420

15-
test('should successfully update a new collection', async () => {
16-
const testNewCollectionAlias = 'updateCollection-functional-test'
17-
const testNewCollection = createCollectionDTO(testNewCollectionAlias)
18-
await createCollection.execute(testNewCollection)
19-
const testNewName = 'Updated Name'
20-
testNewCollection.name = testNewName
21-
expect.assertions(1)
22-
try {
23-
await updateCollection.execute(testNewCollectionAlias, testNewCollection)
24-
} catch (error) {
25-
throw new Error('Collection should be updated')
26-
} finally {
27-
const updatedCollection = await getCollection.execute(testNewCollectionAlias)
28-
expect(updatedCollection.name).toBe(testNewName)
29-
}
30-
})
21+
test('should successfully update a new collection', async () => {
22+
const testNewCollectionAlias = 'updateCollection-functional-test'
23+
const testNewCollection = createCollectionDTO(testNewCollectionAlias)
24+
await createCollection.execute(testNewCollection)
25+
const testNewName = 'Updated Name'
26+
testNewCollection.name = testNewName
27+
expect.assertions(1)
28+
try {
29+
await updateCollection.execute(testNewCollectionAlias, testNewCollection)
30+
} catch (error) {
31+
throw new Error('Collection should be updated')
32+
} finally {
33+
const updatedCollection = await getCollection.execute(testNewCollectionAlias)
34+
expect(updatedCollection.name).toBe(testNewName)
35+
}
36+
})
3137

32-
test('should throw an error when the parent collection does not exist', async () => {
33-
const testNewCollection = createCollectionDTO()
34-
expect.assertions(2)
35-
let writeError: WriteError
36-
try {
37-
await updateCollection.execute(TestConstants.TEST_DUMMY_COLLECTION_ID, testNewCollection)
38-
throw new Error('Use case should throw an error')
39-
} catch (error) {
40-
writeError = error
41-
} finally {
42-
expect(writeError).toBeInstanceOf(WriteError)
43-
expect(writeError.message).toEqual(
44-
`There was an error when writing the resource. Reason was: [404] Can't find dataverse with identifier='${TestConstants.TEST_DUMMY_COLLECTION_ID}'`
45-
)
46-
}
47-
})
38+
test('should throw an error when the parent collection does not exist', async () => {
39+
const testNewCollection = createCollectionDTO()
40+
expect.assertions(2)
41+
let writeError: WriteError
42+
try {
43+
await updateCollection.execute(TestConstants.TEST_DUMMY_COLLECTION_ID, testNewCollection)
44+
throw new Error('Use case should throw an error')
45+
} catch (error) {
46+
writeError = error
47+
} finally {
48+
expect(writeError).toBeInstanceOf(WriteError)
49+
expect(writeError.message).toEqual(
50+
`There was an error when writing the resource. Reason was: [404] Can't find dataverse with identifier='${TestConstants.TEST_DUMMY_COLLECTION_ID}'`
51+
)
52+
}
53+
})
4854
})

0 commit comments

Comments
 (0)