Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ci
name: integration tests

on: [push]

Expand Down
107 changes: 0 additions & 107 deletions tests/integration/catalog.serial.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,113 +111,6 @@ describe("Catalog API", () => {
expect(deleteCatalogObjectsResp.deletedObjectIds).toHaveLength(200);
}, 240_000);

it("should upload catalog image", async () => {
// Add retry logic for the image upload
const maxRetries = 5; // Increased from 3 to 5
let lastError = null;

for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
// If this isn't the first attempt, wait before retrying
if (attempt > 0) {
console.log(`Attempt ${attempt + 1} for image upload...`);
// Increase wait time between retries exponentially
await sleep(2 ** attempt * 5000);
}

console.log(`Starting image upload attempt ${attempt + 1}`);

// Setup: Load a test image file
const imageFile = await getTestFile();
console.log("Test file loaded");

// Setup: Create a catalog object to associate the image with
const catalogObject = createTestCatalogItem();

// Add delay before catalog creation
await sleep(3000);
console.log("Creating catalog object...");

const createCatalogResp = await client.catalog.batchUpsert(
{
idempotencyKey: newTestUuid(),
batches: [
{
objects: [catalogObject],
},
],
},
{
maxRetries: MAX_RETRIES_CATALOG,
timeoutInSeconds: MAX_TIMEOUT,
},
);

console.log("Catalog object created");
expect(createCatalogResp.objects).toHaveLength(1);
const createdCatalogObject = createCatalogResp.objects?.[0];
expect(createdCatalogObject).toBeDefined();

// Add delay before image upload
await sleep(5000);
console.log("Uploading image...");

// Create a new catalog image
const imageName = `Test Image ${newTestUuid()}`;
const createCatalogImageResp = await client.catalog.images.create(
{
imageFile,
request: {
idempotencyKey: newTestUuid(),
objectId: createdCatalogObject?.id,
image: {
type: "IMAGE",
id: newTestSquareTempId(),
imageData: {
name: imageName,
},
},
},
},
{
maxRetries: MAX_RETRIES_CATALOG,
timeoutInSeconds: 180, // Increased timeout for image upload
},
);

console.log("Image uploaded successfully");
expect(createCatalogImageResp.image).toBeDefined();

// Add delay before cleanup
await sleep(3000);
console.log("Starting cleanup...");

// Cleanup: Delete the created catalog object and image
await client.catalog.batchDelete(
{
objectIds: [createdCatalogObject?.id!, createCatalogImageResp.image?.id!],
},
{
maxRetries: MAX_RETRIES_CATALOG,
timeoutInSeconds: MAX_TIMEOUT,
},
);

console.log("Cleanup completed");
// If we get here, the test succeeded, so break out of retry loop
return;
} catch (error) {
lastError = error;
console.log(`Attempt ${attempt + 1} failed with error:`, error);
// If this was the last attempt, the error will be thrown below
}
}

// If we get here, all retries failed
console.log("All image upload attempts failed");
throw lastError;
}, 360_000);

it("should test upsert catalog object", async () => {
const coffee = createTestCatalogItem({
name: "Coffee",
Expand Down