Skip to content

Commit

Permalink
test: update to documents API
Browse files Browse the repository at this point in the history
  • Loading branch information
chohner committed Dec 16, 2024
1 parent 534e97e commit b9d09f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
23 changes: 13 additions & 10 deletions tests/content/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const request = require("supertest");

it("returns single type with populate=deep and locale=all for authenticated users", async () => {
it("returns single type with pLevel and locale=de for authenticated users", async () => {
const defaultRole = await strapi
.query("plugin::users-permissions.role")
.findOne({}, []);
Expand All @@ -16,30 +16,33 @@ it("returns single type with populate=deep and locale=all for authenticated user
};

/** Creates a new user and push to database */
const user = await strapi.plugins["users-permissions"].services.user.add(
mockUserData
);
const user =
await strapi.plugins["users-permissions"].services.user.add(mockUserData);
const jwt = strapi.plugins["users-permissions"].services.jwt.issue({
id: user.id,
});

const paragraphs = [{ id: 1, text: "asd" }];
const paragraphs = [{ text: "asd" }];
const links = [{ text: "Click Me", url: "http://test.link" }];
const data = {
publishedAt: new Date(),
paragraphs,
links,
};
await strapi.entityService.create("api::footer.footer", { data });

await strapi
.documents("api::footer.footer")
.create({ data, locale: "de", status: "published" });

await request(strapi.server.httpServer)
.get("/api/footer?populate=deep&locale=all")
.get("/api/footer?pLevel")
.set("accept", "application/json")
.set("Content-Type", "application/json")
.set("Authorization", "Bearer " + jwt)
.expect("Content-Type", /json/)
.expect(200)
.then((data) => {
expect(data.body).toBeDefined();
expect(data.body.data[0].attributes).toBeDefined();
expect(data.body.data[0].attributes.paragraphs).toEqual(paragraphs);
expect(data.body.data[0]).toBeDefined();
expect(data.body.data[0].paragraphs).toEqual(paragraphs);
});
});
5 changes: 2 additions & 3 deletions tests/helpers/strapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ let instance;

async function setupStrapi() {
if (!instance) {
await Strapi().load();
await Strapi.createStrapi().load();
instance = strapi;

await instance.server.mount();
instance.server.mount();
}
return instance;
}
Expand Down

0 comments on commit b9d09f4

Please sign in to comment.