|
| 1 | +import got from "got" |
| 2 | + |
| 3 | +const baseUrl = `http://fixture` |
| 4 | +const proxyUrl = `http://fixture-proxy` |
| 5 | + |
1 | 6 | jest.mock(`got`, () => |
2 | 7 | jest.fn(path => { |
| 8 | + if (path.includes(proxyUrl)) { |
| 9 | + path = path.replace(proxyUrl, baseUrl) |
| 10 | + } |
| 11 | + |
3 | 12 | let last = `` |
4 | 13 | if (path.includes(`i18n-test`)) { |
5 | 14 | last = `i18n-test-` |
@@ -59,7 +68,6 @@ const { handleWebhookUpdate } = require(`../utils`) |
59 | 68 | describe(`gatsby-source-drupal`, () => { |
60 | 69 | let nodes = {} |
61 | 70 | const createNodeId = id => `generated-id-${id}` |
62 | | - const baseUrl = `http://fixture` |
63 | 71 | const createContentDigest = jest.fn().mockReturnValue(`contentDigest`) |
64 | 72 | const { objectContaining } = expect |
65 | 73 | const actions = { |
@@ -450,6 +458,38 @@ describe(`gatsby-source-drupal`, () => { |
450 | 458 | expect(nodes[createNodeId(`und.article-3`)]).toBeDefined() |
451 | 459 | }) |
452 | 460 |
|
| 461 | + it(`Can use the proxyUrl plugin option to use a different API url for sourcing`, async () => { |
| 462 | + got.mockClear() |
| 463 | + nodes = {} |
| 464 | + await sourceNodes(args, { baseUrl, proxyUrl }) |
| 465 | + |
| 466 | + let callSkipCount = 0 |
| 467 | + for (const [index, call] of got.mock.calls.entries()) { |
| 468 | + if (call[0] === `http://fixture/jsonapi`) { |
| 469 | + callSkipCount++ |
| 470 | + continue |
| 471 | + } |
| 472 | + |
| 473 | + expect(got).toHaveBeenNthCalledWith( |
| 474 | + index + 1, |
| 475 | + expect.stringContaining(proxyUrl), |
| 476 | + expect.anything() |
| 477 | + ) |
| 478 | + } |
| 479 | + |
| 480 | + expect(callSkipCount).toBe(1) |
| 481 | + expect(got).toBeCalledTimes(8) |
| 482 | + |
| 483 | + expect(Object.keys(nodes).length).not.toEqual(0) |
| 484 | + expect(nodes[createNodeId(`und.file-1`)]).toBeDefined() |
| 485 | + expect(nodes[createNodeId(`und.file-2`)]).toBeDefined() |
| 486 | + expect(nodes[createNodeId(`und.tag-1`)]).toBeDefined() |
| 487 | + expect(nodes[createNodeId(`und.tag-2`)]).toBeDefined() |
| 488 | + expect(nodes[createNodeId(`und.article-1`)]).toBeDefined() |
| 489 | + expect(nodes[createNodeId(`und.article-2`)]).toBeDefined() |
| 490 | + expect(nodes[createNodeId(`und.article-3`)]).toBeDefined() |
| 491 | + }) |
| 492 | + |
453 | 493 | it(`Verify JSON:API includes relationships`, async () => { |
454 | 494 | // Reset nodes and test includes relationships. |
455 | 495 | Object.keys(nodes).forEach(key => delete nodes[key]) |
|
0 commit comments