Skip to content

Commit 722fd9b

Browse files
authored
Merge pull request #108 from osu-mist/feature/CO-2036-unit-tests
Feature/CO-2036 unit tests
2 parents 6dfa7df + 7b5ef22 commit 722fd9b

File tree

6 files changed

+596
-5
lines changed

6 files changed

+596
-5
lines changed

src/db/http/onbase-dao.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ const getDocumentContent = async (token, fbLb, documentId) => {
547547
if (err.response && err.response.status === 404) {
548548
logger.error(err.response.data.errors);
549549
return new Error(err.response.data.detail);
550-
} if (err.response && (err.response.status !== 200 || err.response.status !== 206)) {
550+
} if (err.response && !_.includes([200, 206], err.response.status)) {
551551
logger.error(err.response.data.errors);
552552
throw new Error(err.response.data.detail);
553553
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import chai from 'chai';
2+
import proxyquire from 'proxyquire';
3+
4+
import { fakeDocument } from './mock-data';
5+
import { testMultipleResources, createConfigStub, runSerializerSuite } from './test-helpers';
6+
7+
chai.should();
8+
9+
describe('Test documents-serializer', () => {
10+
const configStub = createConfigStub();
11+
const { serializeDocuments, serializeDocument } = proxyquire('serializers/documents-serializer', {});
12+
configStub.restore();
13+
14+
it('serializeDocuments should properly serialize multiple documents in JSON API format', () => {
15+
const result = serializeDocuments([fakeDocument, fakeDocument], '');
16+
return testMultipleResources(result);
17+
});
18+
19+
runSerializerSuite('serializeDocument', 'a single document', serializeDocument);
20+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import chai from 'chai';
2+
import proxyquire from 'proxyquire';
3+
4+
import { createConfigStub, runSerializerSuite } from './test-helpers';
5+
6+
chai.should();
7+
8+
describe('Test keywords-serializer', () => {
9+
const configStub = createConfigStub();
10+
const { serializeKeywords } = proxyquire('serializers/keywords-serializer', {});
11+
configStub.restore();
12+
13+
runSerializerSuite('serializeKeywords', 'keywords collection', serializeKeywords);
14+
});

src/tests/unit/mock-data.js

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,59 @@
11
const fakeOsuId = '999999999';
22
const fakeBaseUrl = '/v2';
3+
const fakeDocument = { typeId: 'fake id' };
34

4-
export { fakeOsuId, fakeBaseUrl };
5+
const docType1 = {
6+
id: '24680',
7+
name: 'TestDocType',
8+
typeId: '924680',
9+
};
10+
const fakeData = {
11+
data: {
12+
access_token: 'fake token',
13+
keywordGuid: 'fake guid',
14+
keywordCollection: 'fake keyword collection',
15+
id: 'fake id',
16+
items: [docType1],
17+
},
18+
};
19+
20+
const keyword1 = {
21+
name: 'Keyword1',
22+
typeId: '924680',
23+
keywordTypeId: '924680',
24+
};
25+
const keyword2 = {
26+
name: 'Keyword2',
27+
typeId: '9123456',
28+
keywordTypeId: '9123456',
29+
};
30+
const keywordType1 = {
31+
id: '924680',
32+
name: 'KeywordType1',
33+
};
34+
const keywordType2 = {
35+
id: '9123456',
36+
name: 'KeywordType2',
37+
};
38+
const fakeKeywordsTypesData = {
39+
data: {
40+
access_token: 'fake token',
41+
keywordGuid: 'fake guid',
42+
keywordCollection: 'fake keyword collection',
43+
id: 'fake id',
44+
items: [keywordType1, keywordType2],
45+
},
46+
};
47+
48+
export {
49+
fakeOsuId,
50+
fakeBaseUrl,
51+
fakeDocument,
52+
docType1,
53+
fakeData,
54+
keyword1,
55+
keyword2,
56+
keywordType1,
57+
keywordType2,
58+
fakeKeywordsTypesData,
59+
};

0 commit comments

Comments
 (0)