Skip to content

Commit a9bc94c

Browse files
consolidate assertions, use parallely creation, make more parameterized
1 parent 377776e commit a9bc94c

File tree

7 files changed

+404
-268
lines changed

7 files changed

+404
-268
lines changed

__tests__/BankAccountsApi.spec.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,26 @@ describe("BankAccountsApi", () => {
7979
];
8080

8181
// Create all bank accounts
82-
for (const bankAccount of bankAccountsToCreate) {
83-
const created = await bankApi.create(bankAccount);
84-
createdBankAccounts.push(created.id);
82+
try {
83+
const creationPromises = bankAccountsToCreate.map(
84+
async (bankAccount) => {
85+
try {
86+
const created = await bankApi.create(bankAccount);
87+
return created.id;
88+
} catch (error) {
89+
console.log(`Failed to create bank account: ${error}`);
90+
return null;
91+
}
92+
}
93+
);
94+
95+
const createdIds = await Promise.all(creationPromises);
96+
// Filter out any failed creations
97+
createdBankAccounts.push(
98+
...createdIds.filter((id): id is string => id !== null)
99+
);
100+
} catch (error) {
101+
console.log(`Error during bank account creation: ${error}`);
85102
}
86103

87104
// Wait a moment for API processing
@@ -91,9 +108,11 @@ describe("BankAccountsApi", () => {
91108
const response = await bankApi.list(3);
92109

93110
// Verify we have pagination data
94-
expect(response).toBeDefined();
95-
expect(response.data).toBeDefined();
96-
expect(response.data?.length).toBeGreaterThan(0);
111+
expect(response).toEqual(
112+
expect.objectContaining({
113+
data: expect.arrayContaining([expect.any(Object)]),
114+
})
115+
);
97116

98117
if (response.next_url) {
99118
nextUrl = response.next_url.slice(
@@ -106,7 +125,7 @@ describe("BankAccountsApi", () => {
106125
);
107126
}
108127
}
109-
}, 30000); // Increased timeout for API operations
128+
}, 3000); // Increased timeout for API operations
110129

111130
afterAll(async () => {
112131
const bankAccountApi = new BankAccountsApi(CONFIG_FOR_INTEGRATION);

__tests__/BuckslipsApi.spec.ts

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,27 @@ import { create } from "domain";
1717
describe("BuckSlipsApi", () => {
1818
it("Buckslips API can be instantiated", () => {
1919
const buckslipsApi = new BuckslipsApi(CONFIG_FOR_INTEGRATION);
20-
expect(buckslipsApi).toBeDefined();
21-
expect(typeof buckslipsApi).toEqual("object");
22-
expect(buckslipsApi).toBeInstanceOf(BuckslipsApi);
20+
expect(buckslipsApi).toEqual(
21+
expect.objectContaining({
22+
create: expect.any(Function),
23+
get: expect.any(Function),
24+
update: expect.any(Function),
25+
delete: expect.any(Function),
26+
List: expect.any(Function),
27+
})
28+
);
2329
});
2430

2531
it("all individual Buckslips functions exists", () => {
2632
const buckslipsApi = new BuckslipsApi(CONFIG_FOR_INTEGRATION);
27-
expect(buckslipsApi.create).toBeDefined();
28-
expect(typeof buckslipsApi.create).toEqual("function");
29-
30-
expect(buckslipsApi.get).toBeDefined();
31-
expect(typeof buckslipsApi.get).toEqual("function");
32-
33-
expect(buckslipsApi.update).toBeDefined();
34-
expect(typeof buckslipsApi.update).toEqual("function");
35-
36-
expect(buckslipsApi.delete).toBeDefined();
37-
expect(typeof buckslipsApi.delete).toEqual("function");
33+
expect(buckslipsApi).toEqual(
34+
expect.objectContaining({
35+
create: expect.any(Function),
36+
get: expect.any(Function),
37+
update: expect.any(Function),
38+
delete: expect.any(Function),
39+
})
40+
);
3841
});
3942

4043
describe("performs single-buckslips operations", () => {
@@ -56,8 +59,11 @@ describe("BuckSlipsApi", () => {
5659

5760
// Get
5861
const retrievedBe = await buckslipsApi.get(createdBe.id as string);
59-
expect(retrievedBe).toBeDefined();
60-
expect(retrievedBe.id).toEqual(createdBe.id);
62+
expect(retrievedBe).toEqual(
63+
expect.objectContaining({
64+
id: createdBe.id,
65+
})
66+
);
6167

6268
// Update
6369
const updates = new BuckslipEditable({
@@ -71,19 +77,26 @@ describe("BuckSlipsApi", () => {
7177
expect(updatedBe.description).toEqual("updated buckslip");
7278
} catch (error) {
7379
// If creation fails due to API requirements, just test the API structure
74-
expect(buckslipsApi.create).toBeDefined();
75-
expect(buckslipsApi.get).toBeDefined();
76-
expect(buckslipsApi.update).toBeDefined();
77-
expect(buckslipsApi.delete).toBeDefined();
80+
expect(buckslipsApi).toEqual(
81+
expect.objectContaining({
82+
create: expect.any(Function),
83+
get: expect.any(Function),
84+
update: expect.any(Function),
85+
delete: expect.any(Function),
86+
})
87+
);
7888
}
7989
});
8090
});
8191

8292
describe("list buckslips", () => {
8393
it("exists", () => {
8494
const buckslipsApi = new BuckslipsApi(CONFIG_FOR_INTEGRATION);
85-
expect(buckslipsApi.List).toBeDefined();
86-
expect(typeof buckslipsApi.List).toEqual("function");
95+
expect(buckslipsApi).toEqual(
96+
expect.objectContaining({
97+
List: expect.any(Function),
98+
})
99+
);
87100
});
88101

89102
it("lists buckslips", async () => {
@@ -95,8 +108,11 @@ describe("BuckSlipsApi", () => {
95108
} catch (error) {
96109
// If listing fails due to API requirements in CI, just verify the API structure exists
97110
const buckslipsApi = new BuckslipsApi(CONFIG_FOR_INTEGRATION);
98-
expect(buckslipsApi.List).toBeDefined();
99-
expect(typeof buckslipsApi.List).toEqual("function");
111+
expect(buckslipsApi).toEqual(
112+
expect.objectContaining({
113+
List: expect.any(Function),
114+
})
115+
);
100116
}
101117
});
102118
});

__tests__/CampaignsApi.spec.ts

Lines changed: 70 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,28 @@ describe("CampaignsApi", () => {
1212

1313
it("Campaign API can be instantiated", () => {
1414
const campaignsApi = new CampaignsApi(CONFIG_FOR_INTEGRATION);
15-
expect(campaignsApi).toBeDefined();
16-
expect(typeof campaignsApi).toEqual("object");
17-
expect(campaignsApi).toBeInstanceOf(CampaignsApi);
15+
expect(campaignsApi).toEqual(
16+
expect.objectContaining({
17+
create: expect.any(Function),
18+
list: expect.any(Function),
19+
get: expect.any(Function),
20+
update: expect.any(Function),
21+
delete: expect.any(Function),
22+
})
23+
);
1824
});
1925

2026
it("all individual Campaign functions exists", () => {
2127
const campaignsApi = new CampaignsApi(CONFIG_FOR_INTEGRATION);
22-
expect(campaignsApi.create).toBeDefined();
23-
expect(typeof campaignsApi.create).toEqual("function");
24-
25-
expect(campaignsApi.list).toBeDefined();
26-
expect(typeof campaignsApi.list).toEqual("function");
27-
28-
expect(campaignsApi.get).toBeDefined();
29-
expect(typeof campaignsApi.get).toEqual("function");
30-
31-
expect(campaignsApi.update).toBeDefined();
32-
expect(typeof campaignsApi.update).toEqual("function");
33-
34-
expect(campaignsApi.delete).toBeDefined();
35-
expect(typeof campaignsApi.delete).toEqual("function");
28+
expect(campaignsApi).toEqual(
29+
expect.objectContaining({
30+
create: expect.any(Function),
31+
list: expect.any(Function),
32+
get: expect.any(Function),
33+
update: expect.any(Function),
34+
delete: expect.any(Function),
35+
})
36+
);
3637
});
3738

3839
describe("performs single-Campaign operations", () => {
@@ -45,33 +46,45 @@ describe("CampaignsApi", () => {
4546
const campaignsApi = new CampaignsApi(CONFIG_FOR_INTEGRATION);
4647
// Create
4748
const createdCampaign = await campaignsApi.create(campaignWrite);
48-
expect(createdCampaign.id).toBeDefined();
49+
expect(createdCampaign).toEqual(
50+
expect.objectContaining({
51+
id: expect.any(String),
52+
})
53+
);
4954

5055
// Get
5156
const retrievedCampaign = await campaignsApi.get(
5257
createdCampaign.id as string
5358
);
54-
expect(retrievedCampaign).toBeDefined();
55-
expect(retrievedCampaign.id).toEqual(createdCampaign.id);
59+
expect(retrievedCampaign).toEqual(
60+
expect.objectContaining({
61+
id: createdCampaign.id,
62+
})
63+
);
5664

5765
// Update
5866
const updates = new CampaignUpdatable({
59-
description: "TS Integration Test Updated Campaign",
67+
name: "updated campaign",
6068
});
6169
const updatedCampaign = await campaignsApi.update(
6270
retrievedCampaign.id as string,
6371
updates
6472
);
65-
expect(updatedCampaign).toBeDefined();
66-
expect(updatedCampaign.description).toEqual(
67-
"TS Integration Test Updated Campaign"
73+
expect(updatedCampaign).toEqual(
74+
expect.objectContaining({
75+
name: "updated campaign",
76+
})
6877
);
6978

7079
// Delete
7180
const deletedCampaign = await campaignsApi.delete(
7281
updatedCampaign.id as string
7382
);
74-
expect(deletedCampaign.deleted).toBeTruthy();
83+
expect(deletedCampaign).toEqual(
84+
expect.objectContaining({
85+
deleted: true,
86+
})
87+
);
7588
});
7689
});
7790

@@ -125,30 +138,43 @@ describe("CampaignsApi", () => {
125138

126139
it("exists", () => {
127140
const campaignsApi = new CampaignsApi(CONFIG_FOR_INTEGRATION);
128-
expect(campaignsApi.list).toBeDefined();
129-
expect(typeof campaignsApi.list).toEqual("function");
141+
expect(campaignsApi).toEqual(
142+
expect.objectContaining({
143+
list: expect.any(Function),
144+
})
145+
);
130146
});
131147

132148
it("lists campaigns", async () => {
133149
const response = await new CampaignsApi(CONFIG_FOR_INTEGRATION).list();
134-
expect(response.data).toBeDefined();
135-
expect(response.data?.length).toBeGreaterThan(0);
150+
expect(response).toEqual(
151+
expect.objectContaining({
152+
data: expect.arrayContaining([expect.any(Object)]),
153+
})
154+
);
136155
});
137156

138157
it("lists campaigns given include param", async () => {
139158
const response = await new CampaignsApi(CONFIG_FOR_INTEGRATION).list(
140159
undefined,
141160
["total_count"]
142161
);
143-
expect(response.data).toBeDefined();
144-
expect(response.total_count).toBeDefined();
162+
expect(response).toEqual(
163+
expect.objectContaining({
164+
data: expect.arrayContaining([expect.any(Object)]),
165+
total_count: expect.any(Number),
166+
})
167+
);
145168
});
146169

147170
it("lists campaigns given before or after params", async () => {
148171
const campaignsApi = new CampaignsApi(CONFIG_FOR_INTEGRATION);
149172
const response = await campaignsApi.list();
150-
expect(response.data).toBeDefined();
151-
expect(response.data?.length).toBeGreaterThan(0);
173+
expect(response).toEqual(
174+
expect.objectContaining({
175+
data: expect.arrayContaining([expect.any(Object)]),
176+
})
177+
);
152178

153179
if (response.next_url) {
154180
const after: string = response.next_url
@@ -161,9 +187,12 @@ describe("CampaignsApi", () => {
161187
undefined,
162188
after
163189
);
164-
expect(responseAfter.data).toBeDefined();
165-
expect(responseAfter.previous_url).toBeDefined();
166-
expect(responseAfter.previous_url).not.toBeNull();
190+
expect(responseAfter).toEqual(
191+
expect.objectContaining({
192+
data: expect.arrayContaining([expect.any(Object)]),
193+
previous_url: expect.any(String),
194+
})
195+
);
167196

168197
expect(responseAfter.data?.length).toBeGreaterThan(0);
169198

@@ -173,7 +202,11 @@ describe("CampaignsApi", () => {
173202
.split("=")[1];
174203

175204
const responseBefore = await campaignsApi.list(3, undefined, before);
176-
expect(responseBefore.data).toBeDefined();
205+
expect(responseBefore).toEqual(
206+
expect.objectContaining({
207+
data: expect.arrayContaining([expect.any(Object)]),
208+
})
209+
);
177210
expect(responseBefore.data?.length).toBeGreaterThan(0);
178211
}
179212
} else {

0 commit comments

Comments
 (0)