mirror of
https://github.com/strapi/strapi.git
synced 2025-08-25 17:19:46 +00:00
test: filtering on components and associations
This commit is contained in:
parent
82afe56cec
commit
ee9df65e67
@ -51,6 +51,13 @@ const labelModel = {
|
|||||||
collectionName: '',
|
collectionName: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const COLORS = {
|
||||||
|
tomato: { name: 'tomato', red: 255, green: 99, blue: 71 },
|
||||||
|
red: { name: 'red', red: 255, green: 0, blue: 0 },
|
||||||
|
green: { name: 'green', red: 0, green: 255, blue: 0 },
|
||||||
|
blue: { name: 'blue', red: 0, green: 0, blue: 255 },
|
||||||
|
};
|
||||||
|
|
||||||
describe('Test Graphql Components API End to End', () => {
|
describe('Test Graphql Components API End to End', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await builder.addComponent(rgbColorComponent).addContentTypes([labelModel]).build();
|
await builder.addComponent(rgbColorComponent).addContentTypes([labelModel]).build();
|
||||||
@ -76,11 +83,12 @@ describe('Test Graphql Components API End to End', () => {
|
|||||||
const data = {
|
const data = {
|
||||||
labels: [],
|
labels: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const labelsPayload = [
|
const labelsPayload = [
|
||||||
{
|
{
|
||||||
name: 'label 3, repeatable and non-repeatable',
|
name: 'label 3, repeatable and non-repeatable',
|
||||||
color: { name: 'tomato', red: 255, green: 99, blue: 71 },
|
color: COLORS.tomato,
|
||||||
colors: [{ name: 'red', red: 255, green: 0, blue: 0 }],
|
colors: [COLORS.red, COLORS.green, COLORS.blue],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -175,16 +183,8 @@ describe('Test Graphql Components API End to End', () => {
|
|||||||
{
|
{
|
||||||
labels_connection {
|
labels_connection {
|
||||||
data {
|
data {
|
||||||
id
|
|
||||||
attributes {
|
attributes {
|
||||||
name
|
colors(filters: { red: { eq: ${COLORS.red.red} } }) {
|
||||||
color {
|
|
||||||
name
|
|
||||||
red
|
|
||||||
green
|
|
||||||
blue
|
|
||||||
}
|
|
||||||
colors(filters: { red: { eq: 255 } }) {
|
|
||||||
name
|
name
|
||||||
red
|
red
|
||||||
green
|
green
|
||||||
@ -200,10 +200,10 @@ describe('Test Graphql Components API End to End', () => {
|
|||||||
const { body } = res;
|
const { body } = res;
|
||||||
|
|
||||||
expect(res.statusCode).toBe(200);
|
expect(res.statusCode).toBe(200);
|
||||||
expect(body).toMatchObject({
|
expect(body).toStrictEqual({
|
||||||
data: {
|
data: {
|
||||||
labels_connection: {
|
labels_connection: {
|
||||||
data: expect.arrayContaining(data.labels),
|
data: [{ attributes: { colors: [COLORS.red] } }],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -533,6 +533,53 @@ describe('Test Graphql Relations API End to End', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Relation filtering', async () => {
|
||||||
|
const res = await graphqlQuery({
|
||||||
|
query: /* GraphQL */ `
|
||||||
|
{
|
||||||
|
articles_connection {
|
||||||
|
data {
|
||||||
|
documentId
|
||||||
|
attributes {
|
||||||
|
name
|
||||||
|
labels_connection(filters: { name: { endsWith: "Color" } }) {
|
||||||
|
data {
|
||||||
|
documentId
|
||||||
|
attributes {
|
||||||
|
name
|
||||||
|
color {
|
||||||
|
name
|
||||||
|
red
|
||||||
|
green
|
||||||
|
blue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { body } = res;
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
expect(body.data?.articles_connection?.data).toBeInstanceOf(Array);
|
||||||
|
|
||||||
|
body.data.articles_connection.data.forEach((article) => {
|
||||||
|
const { data: labels } = article.attributes.labels_connection;
|
||||||
|
expect(labels).toBeInstanceOf(Array);
|
||||||
|
|
||||||
|
for (const label of labels) {
|
||||||
|
expect(label.attributes).toMatchObject(
|
||||||
|
expect.objectContaining({ name: expect.stringMatching(/.*Color$/) })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('Update Article relations removes correctly a relation', async () => {
|
test('Update Article relations removes correctly a relation', async () => {
|
||||||
const article = data.articles[0];
|
const article = data.articles[0];
|
||||||
const labels = [data.labels[0]];
|
const labels = [data.labels[0]];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user