-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated content api to be searchable in PB Editor (#2137)
* updated content api to be searchable in PB Editor * added gallery and video content sources * updated imports
- Loading branch information
1 parent
7506a0f
commit 8a5279e
Showing
5 changed files
with
331 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
blocks/content-api-source-block/sources/content-api-gallery.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import contentAPI from "./content-api"; | ||
|
||
export default { | ||
...contentAPI, | ||
searchable: "gallery", | ||
}; |
159 changes: 159 additions & 0 deletions
159
blocks/content-api-source-block/sources/content-api-gallery.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import contentApi from "./content-api-gallery"; | ||
|
||
jest.mock("fusion:environment", () => ({ | ||
CONTENT_BASE: "https://content.base", | ||
})); | ||
|
||
jest.mock("axios", () => ({ | ||
__esModule: true, | ||
default: jest.fn((request) => { | ||
const requestUrl = new URL(request.url); | ||
const url = { | ||
hostname: requestUrl.hostname, | ||
pathname: requestUrl.pathname, | ||
searchObject: Object.fromEntries(requestUrl.searchParams), | ||
}; | ||
if (request.url.includes("302Mode")) { | ||
return Promise.resolve({ | ||
data: { | ||
type: "story", | ||
related_content: { | ||
redirect: [{ redirect_url: "test_url" }], | ||
}, | ||
request: { | ||
...request, | ||
url, | ||
}, | ||
}, | ||
}); | ||
} | ||
return Promise.resolve({ | ||
data: { | ||
content_elements: [{ url }], | ||
request: { | ||
...request, | ||
url, | ||
}, | ||
}, | ||
}); | ||
}), | ||
})); | ||
|
||
describe("the content api source block", () => { | ||
it("should use the proper param types", () => { | ||
expect(contentApi.params).toEqual([ | ||
{ | ||
displayName: "_id", | ||
name: "_id", | ||
type: "text", | ||
}, | ||
{ | ||
displayName: "website_url", | ||
name: "website_url", | ||
type: "text", | ||
}, | ||
{ | ||
default: "2", | ||
displayName: "Themes Version", | ||
name: "themes", | ||
type: "text", | ||
}, | ||
]); | ||
}); | ||
|
||
describe("when a site is provided", () => { | ||
it('should include the "website" query param with the value', async () => { | ||
const contentSourceFetch = await contentApi.fetch( | ||
{ | ||
"arc-site": "wapo", | ||
website_url: "/aaaa/bccccd/", | ||
}, | ||
{ cachedCall: () => {} }, | ||
); | ||
|
||
expect(contentSourceFetch.request.url.pathname).toEqual("/content/v4/"); | ||
expect(contentSourceFetch.request.url.searchObject).toEqual( | ||
expect.objectContaining({ | ||
website: "wapo", | ||
website_url: "/aaaa/bccccd/", | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
describe("when a site is NOT provided but a website url is ", () => { | ||
it('should NOT include the "website" query param', async () => { | ||
const contentSourceFetch = await contentApi.fetch( | ||
{ | ||
website_url: "/aaaa/bccccd/", | ||
}, | ||
{ cachedCall: () => {} }, | ||
); | ||
|
||
expect(contentSourceFetch.request.url.pathname).toEqual("/content/v4/"); | ||
expect(contentSourceFetch.request.url.searchObject).toEqual( | ||
expect.objectContaining({ | ||
website_url: "/aaaa/bccccd/", | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
describe("when an _id is provided", () => { | ||
it("should set the _id query param", async () => { | ||
const contentSourceFetch = await contentApi.fetch( | ||
{ | ||
_id: "myid", | ||
}, | ||
{ cachedCall: () => {} }, | ||
); | ||
|
||
expect(contentSourceFetch.request.url.pathname).toEqual("/content/v4/"); | ||
expect(contentSourceFetch.request.url.searchObject).toEqual( | ||
expect.objectContaining({ | ||
_id: "myid", | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
describe("when an _id and website_url are both provided", () => { | ||
it("should set the _id query param", async () => { | ||
const contentSourceFetch = await contentApi.fetch( | ||
{ | ||
_id: "myid", | ||
website_url: "/aaaa/eeeeee/", | ||
}, | ||
{ cachedCall: () => {} }, | ||
); | ||
|
||
expect(contentSourceFetch.request.url.pathname).toEqual("/content/v4/"); | ||
expect(contentSourceFetch.request.url.searchObject).toEqual( | ||
expect.objectContaining({ | ||
_id: "myid", | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
describe("when a website url is and an id are NOT provided", () => { | ||
it("should have an undefined website_url", async () => { | ||
const contentSourceFetch = await contentApi.fetch({}, { cachedCall: () => {} }); | ||
|
||
expect(contentSourceFetch.request.url.pathname).toEqual("/content/v4/"); | ||
expect(contentSourceFetch.request.url.searchObject).toEqual( | ||
expect.objectContaining({ | ||
website_url: "undefined", | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
describe("When a redirect is set", () => { | ||
it("should throw a 302", async () => { | ||
await expect(() => | ||
contentApi.fetch({ _id: "302Mode" }, { cachedCall: () => {} }), | ||
).rejects.toEqual(new Error("Redirect")); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import contentAPI from "./content-api"; | ||
|
||
export default { | ||
...contentAPI, | ||
searchable: "video", | ||
}; |
159 changes: 159 additions & 0 deletions
159
blocks/content-api-source-block/sources/content-api-video.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import contentApi from "./content-api-video"; | ||
|
||
jest.mock("fusion:environment", () => ({ | ||
CONTENT_BASE: "https://content.base", | ||
})); | ||
|
||
jest.mock("axios", () => ({ | ||
__esModule: true, | ||
default: jest.fn((request) => { | ||
const requestUrl = new URL(request.url); | ||
const url = { | ||
hostname: requestUrl.hostname, | ||
pathname: requestUrl.pathname, | ||
searchObject: Object.fromEntries(requestUrl.searchParams), | ||
}; | ||
if (request.url.includes("302Mode")) { | ||
return Promise.resolve({ | ||
data: { | ||
type: "story", | ||
related_content: { | ||
redirect: [{ redirect_url: "test_url" }], | ||
}, | ||
request: { | ||
...request, | ||
url, | ||
}, | ||
}, | ||
}); | ||
} | ||
return Promise.resolve({ | ||
data: { | ||
content_elements: [{ url }], | ||
request: { | ||
...request, | ||
url, | ||
}, | ||
}, | ||
}); | ||
}), | ||
})); | ||
|
||
describe("the content api source block", () => { | ||
it("should use the proper param types", () => { | ||
expect(contentApi.params).toEqual([ | ||
{ | ||
displayName: "_id", | ||
name: "_id", | ||
type: "text", | ||
}, | ||
{ | ||
displayName: "website_url", | ||
name: "website_url", | ||
type: "text", | ||
}, | ||
{ | ||
default: "2", | ||
displayName: "Themes Version", | ||
name: "themes", | ||
type: "text", | ||
}, | ||
]); | ||
}); | ||
|
||
describe("when a site is provided", () => { | ||
it('should include the "website" query param with the value', async () => { | ||
const contentSourceFetch = await contentApi.fetch( | ||
{ | ||
"arc-site": "wapo", | ||
website_url: "/aaaa/bccccd/", | ||
}, | ||
{ cachedCall: () => {} }, | ||
); | ||
|
||
expect(contentSourceFetch.request.url.pathname).toEqual("/content/v4/"); | ||
expect(contentSourceFetch.request.url.searchObject).toEqual( | ||
expect.objectContaining({ | ||
website: "wapo", | ||
website_url: "/aaaa/bccccd/", | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
describe("when a site is NOT provided but a website url is ", () => { | ||
it('should NOT include the "website" query param', async () => { | ||
const contentSourceFetch = await contentApi.fetch( | ||
{ | ||
website_url: "/aaaa/bccccd/", | ||
}, | ||
{ cachedCall: () => {} }, | ||
); | ||
|
||
expect(contentSourceFetch.request.url.pathname).toEqual("/content/v4/"); | ||
expect(contentSourceFetch.request.url.searchObject).toEqual( | ||
expect.objectContaining({ | ||
website_url: "/aaaa/bccccd/", | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
describe("when an _id is provided", () => { | ||
it("should set the _id query param", async () => { | ||
const contentSourceFetch = await contentApi.fetch( | ||
{ | ||
_id: "myid", | ||
}, | ||
{ cachedCall: () => {} }, | ||
); | ||
|
||
expect(contentSourceFetch.request.url.pathname).toEqual("/content/v4/"); | ||
expect(contentSourceFetch.request.url.searchObject).toEqual( | ||
expect.objectContaining({ | ||
_id: "myid", | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
describe("when an _id and website_url are both provided", () => { | ||
it("should set the _id query param", async () => { | ||
const contentSourceFetch = await contentApi.fetch( | ||
{ | ||
_id: "myid", | ||
website_url: "/aaaa/eeeeee/", | ||
}, | ||
{ cachedCall: () => {} }, | ||
); | ||
|
||
expect(contentSourceFetch.request.url.pathname).toEqual("/content/v4/"); | ||
expect(contentSourceFetch.request.url.searchObject).toEqual( | ||
expect.objectContaining({ | ||
_id: "myid", | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
describe("when a website url is and an id are NOT provided", () => { | ||
it("should have an undefined website_url", async () => { | ||
const contentSourceFetch = await contentApi.fetch({}, { cachedCall: () => {} }); | ||
|
||
expect(contentSourceFetch.request.url.pathname).toEqual("/content/v4/"); | ||
expect(contentSourceFetch.request.url.searchObject).toEqual( | ||
expect.objectContaining({ | ||
website_url: "undefined", | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
describe("When a redirect is set", () => { | ||
it("should throw a 302", async () => { | ||
await expect(() => | ||
contentApi.fetch({ _id: "302Mode" }, { cachedCall: () => {} }), | ||
).rejects.toEqual(new Error("Redirect")); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,5 @@ export default { | |
fetch, | ||
params, | ||
schemaName: "ans-item", | ||
searchable: "story", | ||
}; |