Skip to content

Commit 0fff979

Browse files
committed
Updated tests to match the test rules and guidelines in CONTRIBUTING.md.
1 parent 5bab5cd commit 0fff979

16 files changed

+386
-333
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
run: npm ci
3636

3737
- name: Run tests and get coverage
38-
run: npm run test
38+
run: npm run test:cov
3939

4040
- name: Upload coverage to Coveralls
4141
uses: coverallsapp/github-action@v2

jest.config.cjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
module.exports = {
22
preset: 'ts-jest',
3-
testPathIgnorePatterns: ['./dist/'],
3+
testPathIgnorePatterns: [
4+
'./dist/',
5+
// Exclude timeout tests by default - they should only run with test:full or test:cov
6+
'./src/tests/timeout-handling/'
7+
],
48
};

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"start": "ts-node src/index.ts",
1212
"lint": "eslint .",
1313
"lint:fix": "eslint . --fix",
14-
"test": "jest --forceExit --coverage --runInBand"
14+
"test": "jest --silent --verbose=false",
15+
"test:full": "jest --forceExit --runInBand --testPathIgnorePatterns='./dist/' --silent --verbose=false",
16+
"test:cov": "jest --forceExit --coverage --runInBand --testPathIgnorePatterns='./dist/' --silent --verbose=false"
1517
},
1618
"repository": {
1719
"type": "git",

src/attachments-streaming/attachments-streaming-pool.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ describe('AttachmentsStreamingPool', () => {
274274
});
275275
});
276276

277-
describe('edge cases', () => {
277+
describe('[Edges]', () => {
278278
it('should handle single attachment', async () => {
279279
mockAdapter.processAttachment.mockResolvedValue({});
280280

src/common/helpers.test.ts

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,37 +51,7 @@ describe(getFilesToLoad.name, () => {
5151
];
5252
});
5353

54-
it('should return an empty array if statsFile is empty', () => {
55-
statsFile = [];
56-
const itemTypesToLoad: ItemTypeToLoad[] = [];
57-
const result = getFilesToLoad({
58-
supportedItemTypes: itemTypesToLoad.map((it) => it.itemType),
59-
statsFile,
60-
});
61-
expect(result).toEqual([]);
62-
});
63-
64-
it('should return an empty array if itemTypesToLoad is empty', () => {
65-
const itemTypesToLoad: ItemTypeToLoad[] = [];
66-
const result = getFilesToLoad({
67-
supportedItemTypes: itemTypesToLoad.map((it) => it.itemType),
68-
statsFile,
69-
});
70-
expect(result).toEqual([]);
71-
});
72-
73-
it('should return an empty array if statsFile has no matching items', () => {
74-
const itemTypesToLoad: ItemTypeToLoad[] = [
75-
{ itemType: 'users', create: jest.fn(), update: jest.fn() },
76-
];
77-
const result = getFilesToLoad({
78-
supportedItemTypes: itemTypesToLoad.map((it) => it.itemType),
79-
statsFile,
80-
});
81-
expect(result).toEqual([]);
82-
});
83-
84-
it('should filter out files not in itemTypesToLoad and order them by itemTypesToLoad', () => {
54+
it('should filter files by supported item types and order them correctly', () => {
8555
const itemTypesToLoad: ItemTypeToLoad[] = [
8656
{ itemType: 'attachments', create: jest.fn(), update: jest.fn() },
8757
{ itemType: 'issues', create: jest.fn(), update: jest.fn() },
@@ -162,4 +132,36 @@ describe(getFilesToLoad.name, () => {
162132
},
163133
]);
164134
});
135+
136+
describe('[Edges]', () => {
137+
it('should return an empty array when statsFile is empty', () => {
138+
statsFile = [];
139+
const itemTypesToLoad: ItemTypeToLoad[] = [];
140+
const result = getFilesToLoad({
141+
supportedItemTypes: itemTypesToLoad.map((it) => it.itemType),
142+
statsFile,
143+
});
144+
expect(result).toEqual([]);
145+
});
146+
147+
it('should return an empty array when itemTypesToLoad is empty', () => {
148+
const itemTypesToLoad: ItemTypeToLoad[] = [];
149+
const result = getFilesToLoad({
150+
supportedItemTypes: itemTypesToLoad.map((it) => it.itemType),
151+
statsFile,
152+
});
153+
expect(result).toEqual([]);
154+
});
155+
156+
it('should return an empty array when statsFile has no matching items', () => {
157+
const itemTypesToLoad: ItemTypeToLoad[] = [
158+
{ itemType: 'users', create: jest.fn(), update: jest.fn() },
159+
];
160+
const result = getFilesToLoad({
161+
supportedItemTypes: itemTypesToLoad.map((it) => it.itemType),
162+
statsFile,
163+
});
164+
expect(result).toEqual([]);
165+
});
166+
});
165167
});

src/common/install-initial-domain-mapping.test.ts

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -193,58 +193,60 @@ describe(installInitialDomainMapping.name, () => {
193193
expect(mockAxiosClient.post).toHaveBeenCalledTimes(1);
194194
});
195195

196-
it('should return early with warning when no initial domain mapping provided', async () => {
197-
await installInitialDomainMapping(mockEvent, null as any);
198-
199-
expect(mockConsoleWarn).toHaveBeenCalledWith(
200-
'No initial domain mapping found.'
201-
);
202-
expect(mockAxiosClient.get).not.toHaveBeenCalled();
203-
expect(mockAxiosClient.post).not.toHaveBeenCalled();
204-
});
205-
206-
it('should return early with warning when undefined initial domain mapping provided', async () => {
207-
await installInitialDomainMapping(mockEvent, undefined as any);
208-
209-
expect(mockConsoleWarn).toHaveBeenCalledWith(
210-
'No initial domain mapping found.'
211-
);
212-
expect(mockAxiosClient.get).not.toHaveBeenCalled();
213-
expect(mockAxiosClient.post).not.toHaveBeenCalled();
214-
});
215-
216-
it('should throw error when import slug is missing', async () => {
217-
const snapInResponseWithoutImport = {
218-
data: {
219-
snap_in: {
220-
imports: [],
221-
snap_in_version: { slug: 'snap-in-slug-123' },
196+
describe('[Edges]', () => {
197+
it('should return early with warning when initial domain mapping is null', async () => {
198+
await installInitialDomainMapping(mockEvent, null as any);
199+
200+
expect(mockConsoleWarn).toHaveBeenCalledWith(
201+
'No initial domain mapping found.'
202+
);
203+
expect(mockAxiosClient.get).not.toHaveBeenCalled();
204+
expect(mockAxiosClient.post).not.toHaveBeenCalled();
205+
});
206+
207+
it('should return early with warning when initial domain mapping is undefined', async () => {
208+
await installInitialDomainMapping(mockEvent, undefined as any);
209+
210+
expect(mockConsoleWarn).toHaveBeenCalledWith(
211+
'No initial domain mapping found.'
212+
);
213+
expect(mockAxiosClient.get).not.toHaveBeenCalled();
214+
expect(mockAxiosClient.post).not.toHaveBeenCalled();
215+
});
216+
217+
it('should throw error when import slug is missing', async () => {
218+
const snapInResponseWithoutImport = {
219+
data: {
220+
snap_in: {
221+
imports: [],
222+
snap_in_version: { slug: 'snap-in-slug-123' },
223+
},
222224
},
223-
},
224-
};
225-
226-
mockAxiosClient.get.mockResolvedValueOnce(snapInResponseWithoutImport);
227-
228-
await expect(
229-
installInitialDomainMapping(mockEvent, mockInitialDomainMapping)
230-
).rejects.toThrow('No import slug or snap-in slug found');
231-
});
232-
233-
it('should throw error when snap-in slug is missing', async () => {
234-
const snapInResponseWithoutSlug = {
235-
data: {
236-
snap_in: {
237-
imports: [{ name: 'import-slug-123' }],
238-
snap_in_version: {},
225+
};
226+
227+
mockAxiosClient.get.mockResolvedValueOnce(snapInResponseWithoutImport);
228+
229+
await expect(
230+
installInitialDomainMapping(mockEvent, mockInitialDomainMapping)
231+
).rejects.toThrow('No import slug or snap-in slug found');
232+
});
233+
234+
it('should throw error when snap-in slug is missing', async () => {
235+
const snapInResponseWithoutSlug = {
236+
data: {
237+
snap_in: {
238+
imports: [{ name: 'import-slug-123' }],
239+
snap_in_version: {},
240+
},
239241
},
240-
},
241-
};
242+
};
242243

243-
mockAxiosClient.get.mockResolvedValueOnce(snapInResponseWithoutSlug);
244+
mockAxiosClient.get.mockResolvedValueOnce(snapInResponseWithoutSlug);
244245

245-
await expect(
246-
installInitialDomainMapping(mockEvent, mockInitialDomainMapping)
247-
).rejects.toThrow('No import slug or snap-in slug found');
246+
await expect(
247+
installInitialDomainMapping(mockEvent, mockInitialDomainMapping)
248+
).rejects.toThrow('No import slug or snap-in slug found');
249+
});
248250
});
249251

250252
it('should handle the error during recipe blueprint creation', async () => {

src/logger/logger.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ describe(Logger.name, () => {
195195
});
196196
});
197197

198-
describe('edge cases', () => {
198+
describe('[Edges]', () => {
199199
let logger: Logger;
200200

201201
beforeEach(() => {

src/repo/repo.test.ts

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ describe(Repo.name, () => {
2626
jest.clearAllMocks();
2727
});
2828

29-
it('should not push items if items array is empty', async () => {
30-
await repo.push([]);
31-
expect(repo.getItems()).toEqual([]);
32-
});
33-
34-
it('should normalize and push 10 items if array is not empty', async () => {
29+
it('should normalize and push items when array contains items', async () => {
3530
const items = createItems(10);
3631
await repo.push(items);
3732
expect(normalize).toHaveBeenCalledTimes(10);
@@ -40,7 +35,7 @@ describe(Repo.name, () => {
4035
expect(repo.getItems()).toEqual(normalizedItems);
4136
});
4237

43-
it('should not normalize items if normalize function is not provided', async () => {
38+
it('should not normalize items when normalize function is not provided', async () => {
4439
repo = new Repo({
4540
event: createEvent({ eventType: EventType.ExtractionDataStart }),
4641
itemType: 'test_item_type',
@@ -53,36 +48,41 @@ describe(Repo.name, () => {
5348
expect(normalize).not.toHaveBeenCalled();
5449
});
5550

56-
describe('should not normalize items if type is "external_domain_metadata" or "ssor_attachment"', () => {
57-
it('item type: external_domain_metadata', async () => {
58-
repo = new Repo({
59-
event: createEvent({ eventType: EventType.ExtractionDataStart }),
60-
itemType: AIRDROP_DEFAULT_ITEM_TYPES.EXTERNAL_DOMAIN_METADATA,
61-
normalize,
62-
onUpload: jest.fn(),
63-
options: {},
64-
});
65-
66-
const items = createItems(10);
67-
await repo.push(items);
51+
describe('[Edges]', () => {
52+
it('should not push items when items array is empty', async () => {
53+
await repo.push([]);
54+
expect(repo.getItems()).toEqual([]);
55+
});
56+
});
6857

69-
expect(normalize).not.toHaveBeenCalled();
58+
it('should not normalize items when item type is external_domain_metadata', async () => {
59+
repo = new Repo({
60+
event: createEvent({ eventType: EventType.ExtractionDataStart }),
61+
itemType: AIRDROP_DEFAULT_ITEM_TYPES.EXTERNAL_DOMAIN_METADATA,
62+
normalize,
63+
onUpload: jest.fn(),
64+
options: {},
7065
});
7166

72-
it('item type: ssor_attachment', async () => {
73-
repo = new Repo({
74-
event: createEvent({ eventType: EventType.ExtractionDataStart }),
75-
itemType: AIRDROP_DEFAULT_ITEM_TYPES.SSOR_ATTACHMENT,
76-
normalize,
77-
onUpload: jest.fn(),
78-
options: {},
79-
});
67+
const items = createItems(10);
68+
await repo.push(items);
8069

81-
const items = createItems(10);
82-
await repo.push(items);
70+
expect(normalize).not.toHaveBeenCalled();
71+
});
8372

84-
expect(normalize).not.toHaveBeenCalled();
73+
it('should not normalize items when item type is ssor_attachment', async () => {
74+
repo = new Repo({
75+
event: createEvent({ eventType: EventType.ExtractionDataStart }),
76+
itemType: AIRDROP_DEFAULT_ITEM_TYPES.SSOR_ATTACHMENT,
77+
normalize,
78+
onUpload: jest.fn(),
79+
options: {},
8580
});
81+
82+
const items = createItems(10);
83+
await repo.push(items);
84+
85+
expect(normalize).not.toHaveBeenCalled();
8686
});
8787

8888
it('should leave 5 items in the items array after pushing 2005 items with batch size of 2000', async () => {
@@ -92,19 +92,30 @@ describe(Repo.name, () => {
9292
expect(repo.getItems().length).toBe(5);
9393
});
9494

95-
it('should upload 2 batches of 2000 and leave 5 items in the items array after pushing 4005 items with batch size of 2000', async () => {
96-
const uploadSpy = jest.spyOn(repo, 'upload');
97-
95+
it('should normalize all items when pushing 4005 items with batch size of 2000', async () => {
9896
const items = createItems(4005);
9997
await repo.push(items);
10098

10199
expect(normalize).toHaveBeenCalledTimes(4005);
102-
expect(repo.getItems().length).toBe(5);
103-
expect(uploadSpy).toHaveBeenCalledTimes(2); // Check that upload was called twice
100+
});
101+
102+
it('should upload 2 batches when pushing 4005 items with batch size of 2000', async () => {
103+
const uploadSpy = jest.spyOn(repo, 'upload');
104104

105+
const items = createItems(4005);
106+
await repo.push(items);
107+
108+
expect(uploadSpy).toHaveBeenCalledTimes(2);
105109
uploadSpy.mockRestore();
106110
});
107111

112+
it('should leave 5 items in array after pushing 4005 items with batch size of 2000', async () => {
113+
const items = createItems(4005);
114+
await repo.push(items);
115+
116+
expect(repo.getItems().length).toBe(5);
117+
});
118+
108119
describe('should take batch size into account', () => {
109120
beforeEach(() => {
110121
repo = new Repo({
@@ -131,17 +142,28 @@ describe(Repo.name, () => {
131142
expect(repo.getItems().length).toBe(5);
132143
});
133144

134-
it('should upload 4 batches of 50 and leave 5 items in the items array after pushing 205 items with batch size of 50', async () => {
145+
it('should normalize all items when pushing 205 items with batch size of 50', async () => {
146+
const items = createItems(205);
147+
await repo.push(items);
148+
149+
expect(normalize).toHaveBeenCalledTimes(205);
150+
});
151+
152+
it('should upload 4 batches when pushing 205 items with batch size of 50', async () => {
135153
const uploadSpy = jest.spyOn(repo, 'upload');
136154

137155
const items = createItems(205);
138156
await repo.push(items);
139157

140-
expect(normalize).toHaveBeenCalledTimes(205);
141-
expect(repo.getItems().length).toBe(5);
142158
expect(uploadSpy).toHaveBeenCalledTimes(4);
143-
144159
uploadSpy.mockRestore();
145160
});
161+
162+
it('should leave 5 items in array after pushing 205 items with batch size of 50', async () => {
163+
const items = createItems(205);
164+
await repo.push(items);
165+
166+
expect(repo.getItems().length).toBe(5);
167+
});
146168
});
147169
});

0 commit comments

Comments
 (0)