Skip to content

Commit 3f01d69

Browse files
committed
Format code
1 parent a1d3d46 commit 3f01d69

File tree

4 files changed

+41
-54
lines changed

4 files changed

+41
-54
lines changed

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,26 @@ test: build
2020
npm run test
2121

2222
.PHONY: prettier
23-
prettier:
23+
prettier: deps
2424
npm run prettier
2525

2626
.PHONY: prettier-check
2727
prettier-check: deps
2828
npx prettier --config .prettierrc 'src/**/*.ts' --check
2929

30+
.PHONY: ci-check
31+
ci-check: build prettier
32+
@echo "Checking for uncommitted changes..."
33+
@if ! git diff --quiet --exit-code; then \
34+
echo "❌ Error: Files were modified by 'make build' or 'make prettier'"; \
35+
echo "Modified files:"; \
36+
git diff --name-only; \
37+
echo ""; \
38+
echo "Please run 'make build' and 'make prettier' locally and commit the changes."; \
39+
exit 1; \
40+
fi
41+
@echo "✅ No uncommitted changes detected"
42+
3043
.PHONY: publish
3144
publish: test
3245
npm publish

src/channels.spec.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,12 @@ describe("pollForAirgapReleaseStatus", () => {
117117

118118
describe("getDownloadUrlAirgapBuildRelease", () => {
119119
let mockServer: mockttp.Mockttp;
120-
let apiClient: VendorPortalApi;
120+
const apiClient = new VendorPortalApi();
121+
apiClient.apiToken = "abcd1234";
121122

122123
beforeEach(async () => {
123124
mockServer = mockttp.getLocal();
124125
await mockServer.start();
125-
// Ensure server is fully ready
126-
await new Promise(resolve => setTimeout(resolve, 5));
127-
apiClient = new VendorPortalApi();
128-
apiClient.apiToken = "abcd1234";
129126
apiClient.endpoint = "http://localhost:" + mockServer.port;
130127
});
131128
afterEach(async () => {
@@ -146,12 +143,8 @@ describe("getDownloadUrlAirgapBuildRelease", () => {
146143
url: "https://s3.amazonaws.com/airgap.replicated.com/xxxxxxxxx/7.airgap?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=xxxxxx%2F20250317%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date="
147144
};
148145

149-
const releasesMock = mockServer.forGet("/app/1234abcd/channel/1/releases").once().thenReply(200, JSON.stringify(releaseData));
150-
const downloadUrlMock = mockServer.forGet("/app/1234abcd/channel/1/airgap/download-url").withQuery({ channelSequence: 1 }).once().thenReply(200, JSON.stringify(downloadUrlData));
151-
152-
// Ensure mocks are set up before making requests
153-
await releasesMock;
154-
await downloadUrlMock;
146+
await mockServer.forGet("/app/1234abcd/channel/1/releases").once().thenReply(200, JSON.stringify(releaseData));
147+
await mockServer.forGet("/app/1234abcd/channel/1/airgap/download-url").withQuery({ channelSequence: 1 }).once().thenReply(200, JSON.stringify(downloadUrlData));
155148

156149
const downloadUrlResult = await getDownloadUrlAirgapBuildRelease(apiClient, "1234abcd", "1", 0);
157150
expect(downloadUrlResult).toEqual("https://s3.amazonaws.com/airgap.replicated.com/xxxxxxxxx/7.airgap?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=xxxxxx%2F20250317%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=");

src/customers.spec.ts

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,12 @@ describe("Create Customer", () => {
7676

7777
describe("List Customers By Name", () => {
7878
let mockServer: mockttp.Mockttp;
79-
let apiClient: VendorPortalApi;
79+
const apiClient = new VendorPortalApi();
80+
apiClient.apiToken = "abcd1234";
8081

8182
beforeEach(async () => {
8283
mockServer = mockttp.getLocal();
8384
await mockServer.start();
84-
// Ensure server is fully ready
85-
await new Promise(resolve => setTimeout(resolve, 5));
86-
apiClient = new VendorPortalApi();
87-
apiClient.apiToken = "abcd1234";
8885
apiClient.endpoint = "http://localhost:" + mockServer.port;
8986
});
9087

@@ -95,7 +92,6 @@ describe("List Customers By Name", () => {
9592
it("should return customers matching the name", async () => {
9693
const appId = "test-app-1";
9794
const appSlug = "test-app-1";
98-
const customerName = "UniqueCustomerName123";
9995
const expectedApplications = {
10096
apps: [
10197
{ id: appId, name: "Test App 1", slug: appSlug },
@@ -104,75 +100,64 @@ describe("List Customers By Name", () => {
104100
};
105101
const customersResponse = {
106102
customers: [
107-
{ id: "customer-1", name: customerName },
108-
{ id: "customer-2", name: customerName + " Two" }
103+
{ id: "customer-1", name: "Test Customer" },
104+
{ id: "customer-2", name: "Test Customer Two" }
109105
]
110106
};
111107

112-
const appsMock = mockServer.forGet("/apps").thenReply(200, JSON.stringify(expectedApplications));
113-
const customersMock = mockServer.forGet(`/app/${appId}/customers`).withQuery({ name: customerName }).once().thenReply(200, JSON.stringify(customersResponse));
114-
115-
await appsMock;
116-
await customersMock;
108+
await mockServer.forGet("/apps").once().thenReply(200, JSON.stringify(expectedApplications));
109+
await mockServer.forGet(`/app/${appId}/customers`).withQuery({ name: "Test Customer" }).once().thenReply(200, JSON.stringify(customersResponse));
117110

118-
const customers: CustomerSummary[] = await listCustomersByName(apiClient, appSlug, customerName);
111+
const customers: CustomerSummary[] = await listCustomersByName(apiClient, appSlug, "Test Customer");
119112
expect(customers).toHaveLength(2);
120-
expect(customers[0].name).toEqual(customerName);
113+
expect(customers[0].name).toEqual("Test Customer");
121114
expect(customers[0].customerId).toEqual("customer-1");
122-
expect(customers[1].name).toEqual(customerName + " Two");
115+
expect(customers[1].name).toEqual("Test Customer Two");
123116
expect(customers[1].customerId).toEqual("customer-2");
124117
});
125118

126119
it("should return empty array when no customers match", async () => {
127-
const appId = "test-app-empty";
128-
const appSlug = "test-app-empty";
129120
const expectedApplications = {
130-
apps: [{ id: appId, name: "Test App Empty", slug: appSlug }]
121+
apps: [{ id: "1234abcd", name: "App 1", slug: "app-1" }]
131122
};
132123
const customersResponse = {
133124
customers: []
134125
};
135126

136127
await mockServer.forGet("/apps").once().thenReply(200, JSON.stringify(expectedApplications));
137-
await mockServer.forGet(`/app/${appId}/customers`).withQuery({ name: "NonExistent" }).once().thenReply(200, JSON.stringify(customersResponse));
128+
await mockServer.forGet("/app/1234abcd/customers").withQuery({ name: "NonExistent" }).once().thenReply(200, JSON.stringify(customersResponse));
138129

139-
const customers: CustomerSummary[] = await listCustomersByName(apiClient, appSlug, "NonExistent");
130+
const customers: CustomerSummary[] = await listCustomersByName(apiClient, "app-1", "NonExistent");
140131
expect(customers).toHaveLength(0);
141132
});
142133

143134
it("should return empty array when customers field is undefined", async () => {
144135
const appId = "test-app-2";
145136
const appSlug = "test-app-2";
146-
const customerName = "UndefinedFieldTest456";
147137
const expectedApplications = {
148138
apps: [{ id: appId, name: "Test App 2", slug: appSlug }]
149139
};
150140
const customersResponse = {};
151141

152-
const appsMock = mockServer.forGet("/apps").thenReply(200, JSON.stringify(expectedApplications));
153-
const customersMock = mockServer.forGet(`/app/${appId}/customers`).withQuery({ name: customerName }).once().thenReply(200, JSON.stringify(customersResponse));
154-
155-
await appsMock;
156-
await customersMock;
142+
await mockServer.forGet("/apps").once().thenReply(200, JSON.stringify(expectedApplications));
143+
await mockServer.forGet(`/app/${appId}/customers`).withQuery({ name: "Test" }).once().thenReply(200, JSON.stringify(customersResponse));
157144

158-
const customers: CustomerSummary[] = await listCustomersByName(apiClient, appSlug, customerName);
145+
const customers: CustomerSummary[] = await listCustomersByName(apiClient, appSlug, "Test");
159146
expect(customers).toHaveLength(0);
160147
});
161148

162149
it("should properly URL encode customer name", async () => {
163-
const appId = "test-app-encode";
164-
const appSlug = "test-app-encode";
165150
const expectedApplications = {
166-
apps: [{ id: appId, name: "Test App Encode", slug: appSlug }]
151+
apps: [{ id: "1234abcd", name: "App 1", slug: "app-1" }]
167152
};
168153
const customersResponse = {
169154
customers: [{ id: "customer-1", name: "Customer & Co" }]
170155
};
171156

172157
await mockServer.forGet("/apps").once().thenReply(200, JSON.stringify(expectedApplications));
173-
await mockServer.forGet(`/app/${appId}/customers`).withQuery({ name: "Customer & Co" }).once().thenReply(200, JSON.stringify(customersResponse));
158+
await mockServer.forGet("/app/1234abcd/customers").withQuery({ name: "Customer & Co" }).once().thenReply(200, JSON.stringify(customersResponse));
174159

175-
const customers: CustomerSummary[] = await listCustomersByName(apiClient, appSlug, "Customer & Co");
160+
const customers: CustomerSummary[] = await listCustomersByName(apiClient, "app-1", "Customer & Co");
176161
expect(customers).toHaveLength(1);
177162
expect(customers[0].name).toEqual("Customer & Co");
178163
expect(customers[0].customerId).toEqual("customer-1");
@@ -181,21 +166,17 @@ describe("List Customers By Name", () => {
181166
it("should throw error when API returns non-200 status", async () => {
182167
const appId = "test-app-3";
183168
const appSlug = "test-app-3";
184-
const customerName = "ErrorTest789";
185169
const expectedApplications = {
186170
apps: [{ id: appId, name: "Test App 3", slug: appSlug }]
187171
};
188172

189-
const appsMock = mockServer.forGet("/apps").thenReply(200, JSON.stringify(expectedApplications));
190-
const customersMock = mockServer
173+
await mockServer.forGet("/apps").once().thenReply(200, JSON.stringify(expectedApplications));
174+
await mockServer
191175
.forGet(`/app/${appId}/customers`)
192-
.withQuery({ name: customerName })
176+
.withQuery({ name: "Test" })
193177
.once()
194178
.thenReply(500, JSON.stringify({ error: "Internal Server Error" }));
195179

196-
await appsMock;
197-
await customersMock;
198-
199-
await expect(listCustomersByName(apiClient, appSlug, customerName)).rejects.toThrow("Failed to list customers: Server responded with 500");
180+
await expect(listCustomersByName(apiClient, appSlug, "Test")).rejects.toThrow("Failed to list customers: Server responded with 500");
200181
});
201182
});

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ export { VendorPortalApi } from "./configuration";
22
export { getApplicationDetails } from "./applications";
33
export { Channel, createChannel, getChannelDetails, archiveChannel, pollForAirgapReleaseStatus, getDownloadUrlAirgapBuildRelease } from "./channels";
44
export { ClusterVersion, createCluster, createClusterWithLicense, pollForStatus, getKubeconfig, removeCluster, upgradeCluster, getClusterVersions, createAddonObjectStore, pollForAddonStatus, exposeClusterPort } from "./clusters";
5-
export { KubernetesDistribution, archiveCustomer, createCustomer, getUsedKubernetesDistributions } from "./customers";
5+
export { KubernetesDistribution, CustomerSummary, archiveCustomer, createCustomer, getUsedKubernetesDistributions, listCustomersByName } from "./customers";
66
export { Release, CompatibilityResult, createRelease, createReleaseFromChart, promoteRelease, reportCompatibilityResult } from "./releases";

0 commit comments

Comments
 (0)