Skip to content

Commit e5e2bb7

Browse files
authored
fix(gatsby-source-drupal): find mimetype field (#38056)
1 parent 38fae7a commit e5e2bb7

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

packages/gatsby-source-drupal/src/__tests__/fixtures/file.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@
4949
"value" : "private://forth-image.png"
5050
}
5151
}
52+
},
53+
{
54+
"type": "file--file",
55+
"id": "file-5",
56+
"attributes": {
57+
"id": 5,
58+
"uuid": "file-5",
59+
"filename": "main-image5.png",
60+
"url": "/sites/default/files/main-image5.png",
61+
"mimetype": "image/png"
62+
}
5263
}
5364
],
5465
"links": {}

packages/gatsby-source-drupal/src/__tests__/index.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,15 @@ describe(`gatsby-source-drupal`, () => {
249249
// first call without basicAuth (no fileSystem defined)
250250
// (the first call is actually the 5th because sourceNodes was ran at first with no basicAuth)
251251
expect(createRemoteFileNode).toHaveBeenNthCalledWith(
252-
5,
252+
6,
253253
expect.objectContaining({
254254
url: urls[0],
255255
auth: {},
256256
})
257257
)
258258
// 2nd call with basicAuth (public: fileSystem defined)
259259
expect(createRemoteFileNode).toHaveBeenNthCalledWith(
260-
6,
260+
7,
261261
expect.objectContaining({
262262
url: urls[1],
263263
auth: {
@@ -268,15 +268,15 @@ describe(`gatsby-source-drupal`, () => {
268268
)
269269
// 3rd call without basicAuth (s3: fileSystem defined)
270270
expect(createRemoteFileNode).toHaveBeenNthCalledWith(
271-
7,
271+
8,
272272
expect.objectContaining({
273273
url: urls[2],
274274
auth: {},
275275
})
276276
)
277277
// 4th call with basicAuth (private: fileSystem defined)
278278
expect(createRemoteFileNode).toHaveBeenNthCalledWith(
279-
8,
279+
9,
280280
expect.objectContaining({
281281
url: urls[3],
282282
auth: {
@@ -289,14 +289,14 @@ describe(`gatsby-source-drupal`, () => {
289289

290290
it(`Skips File Downloads on initial build`, async () => {
291291
const skipFileDownloads = true
292-
expect(createRemoteFileNode).toBeCalledTimes(8)
292+
expect(createRemoteFileNode).toBeCalledTimes(10)
293293
await sourceNodes(args, { baseUrl, skipFileDownloads })
294-
expect(createRemoteFileNode).toBeCalledTimes(8)
294+
expect(createRemoteFileNode).toBeCalledTimes(10)
295295
})
296296

297297
it(`Skips File Downloads on webhook update`, async () => {
298298
const skipFileDownloads = true
299-
expect(createRemoteFileNode).toBeCalledTimes(8)
299+
expect(createRemoteFileNode).toBeCalledTimes(10)
300300
const nodeToUpdate = require(`./fixtures/webhook-file-update.json`).data
301301

302302
await handleWebhookUpdate(
@@ -310,7 +310,7 @@ describe(`gatsby-source-drupal`, () => {
310310
}
311311
)
312312

313-
expect(createRemoteFileNode).toBeCalledTimes(8)
313+
expect(createRemoteFileNode).toBeCalledTimes(10)
314314
})
315315

316316
describe(`Update webhook`, () => {
@@ -641,6 +641,30 @@ describe(`gatsby-source-drupal`, () => {
641641
expect(probeImageSize).toHaveBeenCalled()
642642
})
643643

644+
it(`should generate Image CDN node data when mimetype is on "mimetype" field`, async () => {
645+
// Reset nodes and test includes relationships.
646+
Object.keys(nodes).forEach(key => delete nodes[key])
647+
648+
const options = {
649+
baseUrl,
650+
skipFileDownloads: true,
651+
}
652+
653+
// Call onPreBootstrap to set options
654+
await onPreBootstrap(args, options)
655+
await sourceNodes(args, options)
656+
657+
const fileNode = nodes[createNodeId(`und.file-5`)]
658+
expect(fileNode).toBeDefined()
659+
expect(fileNode.url).toEqual(
660+
`http://fixture/sites/default/files/main-image5.png`
661+
)
662+
expect(fileNode.mimeType).toEqual(`image/png`)
663+
expect(fileNode.width).toEqual(100)
664+
expect(fileNode.height).toEqual(100)
665+
expect(probeImageSize).toHaveBeenCalled()
666+
})
667+
644668
it(`should not generate required Image CDN node data when imageCDN option is set to false`, async () => {
645669
// Reset nodes and test includes relationships.
646670
Object.keys(nodes).forEach(key => delete nodes[key])

packages/gatsby-source-drupal/src/normalize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const getGatsbyImageCdnFields = async ({
4747
return {}
4848
}
4949

50-
const mimeType = node.attributes.filemime
50+
const mimeType = node.attributes.filemime || node.attributes.mimetype
5151
const { filename } = node.attributes
5252

5353
if (!mimeType || !filename) {

0 commit comments

Comments
 (0)