diff --git a/e2e/tests/productV1.test.ts b/e2e/tests/productV1.test.ts index dc8bafcff..3da988d72 100644 --- a/e2e/tests/productV1.test.ts +++ b/e2e/tests/productV1.test.ts @@ -44,18 +44,21 @@ function mockProductV1Metadata( productUuid: string = productV1.buildUuid(), overrides: DeepPartial = {} as DeepPartial ): productV1.ProductV1Metadata { + const productV1ValidMinimalOfferClone = JSON.parse( + JSON.stringify(productV1ValidMinimalOffer) + ); return { - ...productV1ValidMinimalOffer, + ...productV1ValidMinimalOfferClone, ...overrides, product: { - ...productV1ValidMinimalOffer.product, + ...productV1ValidMinimalOfferClone.product, ...overrides.product, uuid: productUuid }, uuid: productV1.buildUuid(), type: MetadataType.PRODUCT_V1, exchangePolicy: { - ...productV1ValidMinimalOffer.exchangePolicy, + ...productV1ValidMinimalOfferClone.exchangePolicy, ...overrides.exchangePolicy, template } @@ -308,6 +311,7 @@ describe("ProductV1 e2e tests", () => { ); metadata2 = mockProductV1Metadata("dummy", productUuid1, { + image: "ipfs://QmWJiZrvxs5Z8qXHZWqCvEbahQrfD7aca7x9iGPsa5iEBr", product: { visuals_images: [ { @@ -1138,6 +1142,25 @@ describe("additional tests", () => { // Do not create the offer with this invalid returnPeriod because the subgraph does not support it }); + test("check animationUrl is added to product.visuals_videos", async () => { + const { coreSDK, fundedWallet: sellerWallet } = + await initCoreSDKWithFundedWallet(seedWallet); + + const template = "Hello World!!"; + const metadata = mockProductV1Metadata(template); + metadata.animationUrl = "https://animation.url"; + const { offerArgs } = await createOfferArgs(coreSDK, metadata); + resolveDateValidity(offerArgs); + + const offer = await createOffer(coreSDK, sellerWallet, offerArgs); + expect(offer).toBeTruthy(); + + expect(offer.metadata?.type).toEqual(MetadataType.PRODUCT_V1); + expect( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ((offer?.metadata as any)?.product as any)?.visuals_videos?.length + ).toEqual(1); + }); }); describe("core-sdk-check-exchange-policy", () => { diff --git a/packages/subgraph/src/entities/metadata/product-v1/index.ts b/packages/subgraph/src/entities/metadata/product-v1/index.ts index d2814842d..9fbe013a4 100644 --- a/packages/subgraph/src/entities/metadata/product-v1/index.ts +++ b/packages/subgraph/src/entities/metadata/product-v1/index.ts @@ -52,6 +52,7 @@ export function saveProductV1Metadata( const variant = saveProductV1Variant(offerId, savedVariationIds); const savedProductId = saveProductV1ProductOrOverrides( productObj, + metadataObj, savedProductV1SellerId, false, variant, @@ -73,6 +74,7 @@ export function saveProductV1Metadata( ); const savedProductOverridesId = saveProductV1ProductOrOverrides( convertToObject(metadataObj.get("productOverrides")), + metadataObj, savedProductV1SellerId, true, null, diff --git a/packages/subgraph/src/entities/metadata/product-v1/media.ts b/packages/subgraph/src/entities/metadata/product-v1/media.ts index 019ece36f..77fcde721 100644 --- a/packages/subgraph/src/entities/metadata/product-v1/media.ts +++ b/packages/subgraph/src/entities/metadata/product-v1/media.ts @@ -9,13 +9,19 @@ export function getMediaId(mediaUrl: string, mediaTag: string): string { export function saveProductV1Medias( medias: Array>, - mediaType: string + mediaType: string, + additionalMediaUrl: string = "" ): string[] { const savedMedias: string[] = []; + let addAdditionalMediaUrl = (additionalMediaUrl !== "") for (let i = 0; i < medias.length; i++) { const mediaObject = medias[i]; const mediaUrl = convertToString(mediaObject.get("url")); + + if (mediaUrl.toLowerCase() == additionalMediaUrl.toLowerCase()) { + addAdditionalMediaUrl = false; + } const mediaTag = convertToString(mediaObject.get("tag")); const mediaHeight = convertToInt(mediaObject.get("height")); const mediaWidth = convertToInt(mediaObject.get("width")); @@ -39,5 +45,22 @@ export function saveProductV1Medias( savedMedias.push(mediaId); } + if (addAdditionalMediaUrl) { + const mediaTag = ""; + const mediaId = getMediaId(additionalMediaUrl, mediaTag); + + let media = ProductV1Media.load(mediaId); + + if (!media) { + media = new ProductV1Media(mediaId); + media.url = additionalMediaUrl; + media.tag = mediaTag; + media.type = mediaType as string; + } + media.save(); + + savedMedias.push(mediaId); + } + return savedMedias; } diff --git a/packages/subgraph/src/entities/metadata/product-v1/product.ts b/packages/subgraph/src/entities/metadata/product-v1/product.ts index c1fa5c194..e2042a715 100644 --- a/packages/subgraph/src/entities/metadata/product-v1/product.ts +++ b/packages/subgraph/src/entities/metadata/product-v1/product.ts @@ -56,6 +56,7 @@ export function getSectionId(section: string): string { export function saveProductV1ProductOrOverrides( productOrOverrideObj: TypedMap | null, + metadataObj: TypedMap, productV1SellerId: string | null, isOverride: boolean, variant: string | null, @@ -130,11 +131,14 @@ export function saveProductV1ProductOrOverrides( const visuals_images = convertToObjectArray( productOrOverrideObj.get("visuals_images") ); - const savedImageIds = saveProductV1Medias(visuals_images, "IMAGE"); + const metadataImage = convertToString(metadataObj.get("image")); + const savedImageIds = saveProductV1Medias(visuals_images, "IMAGE", metadataImage); const visuals_videos = convertToObjectArray( productOrOverrideObj.get("visuals_videos") ); - const savedVideoIds = saveProductV1Medias(visuals_videos, "VIDEO"); + const animationUrl = convertToString(metadataObj.get("animationUrl")); + const savedVideoIds = saveProductV1Medias(visuals_videos, "VIDEO", animationUrl); + const packaging_packageQuantity = convertToString( productOrOverrideObj.get("packaging_packageQuantity")