mirror of
https://github.com/strapi/strapi.git
synced 2025-12-30 00:37:24 +00:00
add test for normalizeSearchResults
This commit is contained in:
parent
92b206bcb0
commit
f6afb6f4f4
@ -27,8 +27,8 @@ const FIXTURE_RELATIONS = {
|
||||
},
|
||||
};
|
||||
|
||||
describe('normalizeRelations', () => {
|
||||
test('filters out deleted releations', () => {
|
||||
describe('RelationInputDataManager || normalizeRelations', () => {
|
||||
test('filters out deleted relations', () => {
|
||||
expect(
|
||||
normalizeRelations(FIXTURE_RELATIONS, {
|
||||
modifiedData: { disconnect: [{ id: 1 }] },
|
||||
@ -137,7 +137,7 @@ describe('normalizeRelations', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('allows to connect new relations, eventhough pages is empty', () => {
|
||||
test('allows to connect new relations, even though pages is empty', () => {
|
||||
expect(
|
||||
normalizeRelations(
|
||||
{
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
import { normalizeSearchResults } from '../normalizeSearchResults';
|
||||
|
||||
const FIXTURE_RELATIONS = {
|
||||
data: {
|
||||
pages: [
|
||||
{
|
||||
results: [
|
||||
{
|
||||
id: 3,
|
||||
name: 'Relation 3',
|
||||
publishedAt: '2022-08-24T09:29:11.38',
|
||||
},
|
||||
|
||||
{
|
||||
id: 2,
|
||||
name: 'Relation 2',
|
||||
publishedAt: '',
|
||||
},
|
||||
|
||||
{
|
||||
id: 1,
|
||||
name: 'Relation 1',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
describe('RelationInputDataManager || normalizeRelations', () => {
|
||||
test('add publicationState attribute to each relation', () => {
|
||||
expect(normalizeSearchResults(FIXTURE_RELATIONS, {})).toStrictEqual({
|
||||
data: {
|
||||
pages: [
|
||||
[
|
||||
expect.objectContaining({ publicationState: 'published' }),
|
||||
expect.objectContaining({ publicationState: 'draft' }),
|
||||
expect.objectContaining({ publicationState: false }),
|
||||
],
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('add mainField attribute to each relation', () => {
|
||||
expect(
|
||||
normalizeSearchResults(FIXTURE_RELATIONS, {
|
||||
mainFieldName: 'name',
|
||||
})
|
||||
).toStrictEqual({
|
||||
data: {
|
||||
pages: [
|
||||
[
|
||||
expect.objectContaining({
|
||||
mainField: FIXTURE_RELATIONS.data.pages[0].results[0].name,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
mainField: FIXTURE_RELATIONS.data.pages[0].results[1].name,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
mainField: FIXTURE_RELATIONS.data.pages[0].results[2].name,
|
||||
}),
|
||||
],
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user