Spaces:
Sleeping

File size: 1,831 Bytes
7f81110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { describe, it, expect } from "vitest";
import { ChangeDetectionService } from "../src/modules/shopify/domain/services/ChangeDetectionService";
import { ShopifyEntityType } from "../src/modules/shopify/domain/valueObjects/ShopifyEntityType";

describe("ChangeDetectionService", () => {
    const service = new ChangeDetectionService();
    const productType = ShopifyEntityType.fromString("product");

    it("should return true if imageSignature is missing", () => {
        const payload = { images: [{ id: "1", url: "http://example.com/1.png" }] };
        const stored: any = { payload, imageSignature: null };
        expect(service.needsImageEnrichment(productType, payload, stored)).toBe(true);
    });

    it("should return false if images and signature are unchanged", () => {
        const payload = { images: [{ id: "1", url: "http://example.com/1.png" }] };
        const stored: any = { payload, imageSignature: "sig" };
        expect(service.needsImageEnrichment(productType, payload, stored)).toBe(false);
    });

    it("should return true if image count changed", () => {
        const payload = { images: [{ id: "1", url: "http://example.com/1.png" }, { id: "2", url: "http://example.com/2.png" }] };
        const stored: any = { payload: { images: [{ id: "1", url: "http://example.com/1.png" }] }, imageSignature: "sig" };
        expect(service.needsImageEnrichment(productType, payload, stored)).toBe(true);
    });

    it("should return true if intermediate image URL changed", () => {
        const payload = { images: [{ id: "1", url: "http://example.com/new.png" }] };
        const stored: any = { payload: { images: [{ id: "1", url: "http://example.com/old.png" }] }, imageSignature: "sig" };
        expect(service.needsImageEnrichment(productType, payload, stored)).toBe(true);
    });
});