Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby-source-drupal): find mimetype field #38056

Merged
merged 3 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/gatsby-source-drupal/src/__tests__/fixtures/file.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
Expand Down
40 changes: 32 additions & 8 deletions packages/gatsby-source-drupal/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ 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: {},
})
)
// 2nd call with basicAuth (public: fileSystem defined)
expect(createRemoteFileNode).toHaveBeenNthCalledWith(
6,
7,
expect.objectContaining({
url: urls[1],
auth: {
Expand All @@ -268,15 +268,15 @@ describe(`gatsby-source-drupal`, () => {
)
// 3rd call without basicAuth (s3: fileSystem defined)
expect(createRemoteFileNode).toHaveBeenNthCalledWith(
7,
8,
expect.objectContaining({
url: urls[2],
auth: {},
})
)
// 4th call with basicAuth (private: fileSystem defined)
expect(createRemoteFileNode).toHaveBeenNthCalledWith(
8,
9,
expect.objectContaining({
url: urls[3],
auth: {
Expand All @@ -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(
Expand All @@ -310,7 +310,7 @@ describe(`gatsby-source-drupal`, () => {
}
)

expect(createRemoteFileNode).toBeCalledTimes(8)
expect(createRemoteFileNode).toBeCalledTimes(10)
})

describe(`Update webhook`, () => {
Expand Down Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-source-drupal/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down