From 26fbccbeec1bc6dbc377cfd084d62489d643594f Mon Sep 17 00:00:00 2001 From: Matt Kane <m@mk.gg> Date: Thu, 4 May 2023 11:32:34 +0100 Subject: [PATCH 1/3] fix(gatsby-source-drupal): find mimetype field --- packages/gatsby-source-drupal/src/normalize.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-drupal/src/normalize.ts b/packages/gatsby-source-drupal/src/normalize.ts index d9241bf7a8da3..a65467fdc5253 100644 --- a/packages/gatsby-source-drupal/src/normalize.ts +++ b/packages/gatsby-source-drupal/src/normalize.ts @@ -47,7 +47,7 @@ const getGatsbyImageCdnFields = async ({ return {} } - const mimeType = node.attributes.filemime + const mimeType = node.attributes.filemime || node.attributes.mimetype const { filename } = node.attributes if (!mimeType || !filename) { From 4831c41af84498a0933b464626628c4d07f2a4d4 Mon Sep 17 00:00:00 2001 From: Matt Kane <m@mk.gg> Date: Thu, 4 May 2023 11:43:52 +0100 Subject: [PATCH 2/3] chore: add test --- .../src/__tests__/fixtures/file.json | 11 +++++++++ .../src/__tests__/index.js | 24 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/packages/gatsby-source-drupal/src/__tests__/fixtures/file.json b/packages/gatsby-source-drupal/src/__tests__/fixtures/file.json index fac5c944aaf90..593feee2579d0 100644 --- a/packages/gatsby-source-drupal/src/__tests__/fixtures/file.json +++ b/packages/gatsby-source-drupal/src/__tests__/fixtures/file.json @@ -49,6 +49,17 @@ "value" : "private://forth-image.png" } } + }, + { + "type": "file--file", + "id": "file-5", + "attributes": { + "id": 5, + "uuid": "file-5", + "filename": "main-image5.png", + "url": "/sites/default/files/main-image5.png", + "mimetype": "image/png" + } } ], "links": {} diff --git a/packages/gatsby-source-drupal/src/__tests__/index.js b/packages/gatsby-source-drupal/src/__tests__/index.js index 90d4b322440b1..9198ff994c87b 100644 --- a/packages/gatsby-source-drupal/src/__tests__/index.js +++ b/packages/gatsby-source-drupal/src/__tests__/index.js @@ -641,6 +641,30 @@ describe(`gatsby-source-drupal`, () => { expect(probeImageSize).toHaveBeenCalled() }) + it(`should generate Image CDN node data when mimetype is on "mimetype" field`, async () => { + // Reset nodes and test includes relationships. + Object.keys(nodes).forEach(key => delete nodes[key]) + + const options = { + baseUrl, + skipFileDownloads: true, + } + + // Call onPreBootstrap to set options + await onPreBootstrap(args, options) + await sourceNodes(args, options) + + const fileNode = nodes[createNodeId(`und.file-5`)] + expect(fileNode).toBeDefined() + expect(fileNode.url).toEqual( + `http://fixture/sites/default/files/main-image5.png` + ) + expect(fileNode.mimeType).toEqual(`image/png`) + expect(fileNode.width).toEqual(100) + expect(fileNode.height).toEqual(100) + expect(probeImageSize).toHaveBeenCalled() + }) + it(`should not generate required Image CDN node data when imageCDN option is set to false`, async () => { // Reset nodes and test includes relationships. Object.keys(nodes).forEach(key => delete nodes[key]) From fee36b8652fa7945467a693f4ddb5f64fb330894 Mon Sep 17 00:00:00 2001 From: Matt Kane <m@mk.gg> Date: Thu, 4 May 2023 12:16:37 +0100 Subject: [PATCH 3/3] chore: update tests --- .../gatsby-source-drupal/src/__tests__/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/gatsby-source-drupal/src/__tests__/index.js b/packages/gatsby-source-drupal/src/__tests__/index.js index 9198ff994c87b..95578f5731dfd 100644 --- a/packages/gatsby-source-drupal/src/__tests__/index.js +++ b/packages/gatsby-source-drupal/src/__tests__/index.js @@ -249,7 +249,7 @@ describe(`gatsby-source-drupal`, () => { // first call without basicAuth (no fileSystem defined) // (the first call is actually the 5th because sourceNodes was ran at first with no basicAuth) expect(createRemoteFileNode).toHaveBeenNthCalledWith( - 5, + 6, expect.objectContaining({ url: urls[0], auth: {}, @@ -257,7 +257,7 @@ describe(`gatsby-source-drupal`, () => { ) // 2nd call with basicAuth (public: fileSystem defined) expect(createRemoteFileNode).toHaveBeenNthCalledWith( - 6, + 7, expect.objectContaining({ url: urls[1], auth: { @@ -268,7 +268,7 @@ describe(`gatsby-source-drupal`, () => { ) // 3rd call without basicAuth (s3: fileSystem defined) expect(createRemoteFileNode).toHaveBeenNthCalledWith( - 7, + 8, expect.objectContaining({ url: urls[2], auth: {}, @@ -276,7 +276,7 @@ describe(`gatsby-source-drupal`, () => { ) // 4th call with basicAuth (private: fileSystem defined) expect(createRemoteFileNode).toHaveBeenNthCalledWith( - 8, + 9, expect.objectContaining({ url: urls[3], auth: { @@ -289,14 +289,14 @@ describe(`gatsby-source-drupal`, () => { it(`Skips File Downloads on initial build`, async () => { const skipFileDownloads = true - expect(createRemoteFileNode).toBeCalledTimes(8) + expect(createRemoteFileNode).toBeCalledTimes(10) await sourceNodes(args, { baseUrl, skipFileDownloads }) - expect(createRemoteFileNode).toBeCalledTimes(8) + expect(createRemoteFileNode).toBeCalledTimes(10) }) it(`Skips File Downloads on webhook update`, async () => { const skipFileDownloads = true - expect(createRemoteFileNode).toBeCalledTimes(8) + expect(createRemoteFileNode).toBeCalledTimes(10) const nodeToUpdate = require(`./fixtures/webhook-file-update.json`).data await handleWebhookUpdate( @@ -310,7 +310,7 @@ describe(`gatsby-source-drupal`, () => { } ) - expect(createRemoteFileNode).toBeCalledTimes(8) + expect(createRemoteFileNode).toBeCalledTimes(10) }) describe(`Update webhook`, () => {