From 1d64d24d311327cb834d95b1a9e9840f08f81a9d Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 13 Nov 2023 12:39:51 -0800 Subject: [PATCH] fix: update function tests for 404ing collections (#7575) --- .../nfts/collection/collectionImage.test.ts | 12 +- .../__snapshots__/collection.test.ts.snap | 148 ------------------ functions/nfts/collection/collection.test.ts | 49 +++--- 3 files changed, 31 insertions(+), 178 deletions(-) diff --git a/functions/api/image/nfts/collection/collectionImage.test.ts b/functions/api/image/nfts/collection/collectionImage.test.ts index 95f3a8b225..f5b67dbd13 100644 --- a/functions/api/image/nfts/collection/collectionImage.test.ts +++ b/functions/api/image/nfts/collection/collectionImage.test.ts @@ -7,19 +7,19 @@ const collectionImageUrls = [ 'http://127.0.0.1:3000/api/image/nfts/collection/0x49cf6f5d44e70224e2e23fdcdd2c053f30ada28b', ] -const nonexistentImageUrls = [ - 'http://127.0.0.1:3000/api/image/nfts/collection/0xed5af388653567af2f388e6224dc7c4b3241c545', -] - -test.each([...collectionImageUrls, ...nonexistentImageUrls])('collectionImageUrl', async (url) => { +test.each([...collectionImageUrls])('collectionImageUrl', async (url) => { const response = await fetch(new Request(url)) expect(response.status).toBe(200) expect(response.headers.get('content-type')).toBe('image/png') }) +const nonexistentImageUrls = [ + 'http://127.0.0.1:3000/api/image/nfts/collection/0xed5af388653567af2f388e6224dc7c4b3241c545', +] + const invalidCollectionImageUrls = ['http://127.0.0.1:3000/api/image/nfts/collection/0xd3adb33f'] -test.each(invalidCollectionImageUrls)('invalidAssetImageUrl', async (url) => { +test.each([...invalidCollectionImageUrls, ...nonexistentImageUrls])('invalidAssetImageUrl', async (url) => { const response = await fetch(new Request(url)) expect(response.status).toBeOneOf([404, 500]) }) diff --git a/functions/nfts/collection/__snapshots__/collection.test.ts.snap b/functions/nfts/collection/__snapshots__/collection.test.ts.snap index 34c951d52e..d0c026d8e7 100644 --- a/functions/nfts/collection/__snapshots__/collection.test.ts.snap +++ b/functions/nfts/collection/__snapshots__/collection.test.ts.snap @@ -443,151 +443,3 @@ exports[`should inject metadata for collections 3`] = ` " `; - -exports[`should inject metadata for collections 4`] = ` -" - - - - - Uniswap Interface - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-
- -
- - -" -`; diff --git a/functions/nfts/collection/collection.test.ts b/functions/nfts/collection/collection.test.ts index 165a6d611b..72132887b7 100644 --- a/functions/nfts/collection/collection.test.ts +++ b/functions/nfts/collection/collection.test.ts @@ -16,15 +16,7 @@ const collections = [ }, ] -const nonexistentCollections = [ - { - address: '0xed5af388653567af2f388e6224dc7c4b3241c545', - collectionName: '0xed5af388653567af2f388e6224dc7c4b3241c545', - image: 'http://127.0.0.1:3000/api/image/nfts/collection/0xed5af388653567af2f388e6224dc7c4b3241c545', - }, -] - -test.each([...collections, ...nonexistentCollections])('should inject metadata for collections', async (collection) => { +test.each([...collections])('should inject metadata for collections', async (collection) => { const url = 'http://127.0.0.1:3000/nfts/collection/' + collection.address const body = await fetch(new Request(url)).then((res) => res.text()) expect(body).toMatchSnapshot() @@ -42,24 +34,33 @@ test.each([...collections, ...nonexistentCollections])('should inject metadata f expect(body).toContain(``) }) +const nonexistentCollections = [ + { + address: '0xed5af388653567af2f388e6224dc7c4b3241c545', + }, +] + const invalidCollections = [ { address: '0xd3adb33f', }, ] -test.each(invalidCollections)('should not inject metadata for nonexistent collections', async (collection) => { - const url = 'http://127.0.0.1:3000/nfts/collection/' + collection.address - const body = await fetch(new Request(url)).then((res) => res.text()) - expect(body).not.toContain('og:title') - expect(body).not.toContain('og:image') - expect(body).not.toContain('og:image:width') - expect(body).not.toContain('og:image:height') - expect(body).not.toContain('og:type') - expect(body).not.toContain('og:url') - expect(body).not.toContain('og:image:alt') - expect(body).not.toContain('twitter:card') - expect(body).not.toContain('twitter:title') - expect(body).not.toContain('twitter:image') - expect(body).not.toContain('twitter:image:alt') -}) +test.each([...invalidCollections, ...nonexistentCollections])( + 'should not inject metadata for nonexistent collections', + async (collection) => { + const url = 'http://127.0.0.1:3000/nfts/collection/' + collection.address + const body = await fetch(new Request(url)).then((res) => res.text()) + expect(body).not.toContain('og:title') + expect(body).not.toContain('og:image') + expect(body).not.toContain('og:image:width') + expect(body).not.toContain('og:image:height') + expect(body).not.toContain('og:type') + expect(body).not.toContain('og:url') + expect(body).not.toContain('og:image:alt') + expect(body).not.toContain('twitter:card') + expect(body).not.toContain('twitter:title') + expect(body).not.toContain('twitter:image') + expect(body).not.toContain('twitter:image:alt') + } +)