Skip to content

Commit f1b24e5

Browse files
committed
chore (Snapshot test): Added additional operators to snapshot tests.
- RQBuilder: Changed Entity Service to REST API in JSDoc
1 parent 2b1d9df commit f1b24e5

File tree

4 files changed

+86
-3
lines changed

4 files changed

+86
-3
lines changed

src/rq-builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ export class RQBuilder<
18061806
//<editor-fold desc="Service specific">
18071807
/**
18081808
* @description Set locale code
1809-
* @description Entity Service Specific
1809+
* @description REST API Specific
18101810
* @param {string} code Locale code
18111811
* @example
18121812
* new RQBuilder<TestModel>().locale("ua")
@@ -1836,7 +1836,7 @@ export class RQBuilder<
18361836

18371837
/**
18381838
* @description Set publication state for draft & publish
1839-
* @description Entity Service Specific
1839+
* @description REST API Specific
18401840
* @param {PublicationStates} state Publication state
18411841
* @example
18421842
* new RQBuilder<TestModel>().publicationState("live")
@@ -1867,7 +1867,7 @@ export class RQBuilder<
18671867

18681868
//<editor-fold desc="Build process">
18691869
/**
1870-
* @description Build the current query into the final Strapi Entity Service format
1870+
* @description Build the current query into the final Strapi REST Api format
18711871
* @return Query with dynamically generated query type
18721872
*/
18731873
public build() {

tests/entity-service-query-builder/types-tests/type-snapshot.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ describe("type snapshot", () => {
2020
.eq("nested.name", "value")
2121
)
2222
)
23+
.filterRelation("nestedList", () =>
24+
new SQBuilder<NestedModel>().contains("deepNestedList.deepProp", "test")
25+
)
2326
.populateDynamic("nested", "component.1", () =>
2427
new SQBuilder<NestedModel>().eq("id", "value")
2528
)
@@ -29,6 +32,11 @@ describe("type snapshot", () => {
2932
.populateRelation("nestedList", () =>
3033
new SQBuilder<NestedModel>().eq("name", "value2").field("name")
3134
)
35+
.populate("nestedListOptionalNullableUndefined")
36+
.publicationState("preview")
37+
.locale("en")
38+
.page(1)
39+
.pageSize(30)
3240
.build();
3341

3442
const assignedQuery: {
@@ -48,6 +56,11 @@ describe("type snapshot", () => {
4856
];
4957
}
5058
];
59+
},
60+
{
61+
nestedList: {
62+
$and: [{ deepNestedList: { deepProp: { $contains: "test" } } }];
63+
};
5164
}
5265
];
5366
};
@@ -64,7 +77,12 @@ describe("type snapshot", () => {
6477
fields: ["name"];
6578
filters: { $and: [{ name: { $eq: "value2" } }] };
6679
};
80+
nestedListOptionalNullableUndefined: true;
6781
};
82+
publicationState: "preview";
83+
locale: "en";
84+
page: 1;
85+
pageSize: 30;
6886
} = query;
6987

7088
expect(assignedQuery).toBeDefined();
@@ -87,6 +105,10 @@ describe("type snapshot", () => {
87105
expect(assignedQuery.filters.$and[1].$and[2].$and[1].nested.name.$eq).toBe(
88106
"value"
89107
);
108+
expect(
109+
assignedQuery.filters.$and[2].nestedList.$and[0].deepNestedList.deepProp
110+
.$contains
111+
).toEqual("test");
90112

91113
expect(
92114
assignedQuery.populate.nested.on["component.1"].filters.$and[0].id.$eq
@@ -99,5 +121,12 @@ describe("type snapshot", () => {
99121
expect(assignedQuery.populate.nestedList.filters.$and[0].name.$eq).toBe(
100122
"value2"
101123
);
124+
expect(assignedQuery.populate.nestedListOptionalNullableUndefined).toBe(
125+
true
126+
);
127+
expect(assignedQuery.publicationState).toEqual("preview");
128+
expect(assignedQuery.locale).toEqual("en");
129+
expect(assignedQuery.page).toEqual(1);
130+
expect(assignedQuery.pageSize).toEqual(30);
102131
});
103132
});

tests/query-engine-query-builder/query-engine-type-snapshot.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ describe("Query engine type snapshot", () => {
2323
.eq("nested.name", "value")
2424
)
2525
)
26+
.filterRelation("nestedList", () =>
27+
new QQBuilder<NestedModel>().contains("deepNestedList.deepProp", "test")
28+
)
2629
.populateDynamic("nested", "component.1", () =>
2730
new QQBuilder<NestedModel>().eq("id", "value")
2831
)
@@ -32,6 +35,9 @@ describe("Query engine type snapshot", () => {
3235
.populateRelation("nestedList", () =>
3336
new QQBuilder<NestedModel>().eq("name", "value2").field("name")
3437
)
38+
.populate("nestedListOptionalNullableUndefined")
39+
.start(1)
40+
.limit(30)
3541
.build();
3642

3743
const assignedQuery: {
@@ -51,6 +57,11 @@ describe("Query engine type snapshot", () => {
5157
];
5258
}
5359
];
60+
},
61+
{
62+
nestedList: {
63+
$and: [{ deepNestedList: { deepProp: { $contains: "test" } } }];
64+
};
5465
}
5566
];
5667
};
@@ -67,7 +78,10 @@ describe("Query engine type snapshot", () => {
6778
select: ["name"];
6879
where: { $and: [{ name: { $eq: "value2" } }] };
6980
};
81+
nestedListOptionalNullableUndefined: true;
7082
};
83+
offset: 1;
84+
limit: 30;
7185
} = query;
7286

7387
expect(assignedQuery).toBeDefined();
@@ -91,6 +105,11 @@ describe("Query engine type snapshot", () => {
91105
"value"
92106
);
93107

108+
expect(
109+
assignedQuery.where.$and[2].nestedList.$and[0].deepNestedList.deepProp
110+
.$contains
111+
).toEqual("test");
112+
94113
expect(
95114
assignedQuery.populate.nested.on["component.1"].where.$and[0].id.$eq
96115
).toBe("value");
@@ -101,5 +120,11 @@ describe("Query engine type snapshot", () => {
101120
expect(assignedQuery.populate.nestedList.where.$and[0].name.$eq).toBe(
102121
"value2"
103122
);
123+
expect(assignedQuery.populate.nestedListOptionalNullableUndefined).toBe(
124+
true
125+
);
126+
127+
expect(assignedQuery.offset).toBe(1);
128+
expect(assignedQuery.limit).toBe(30);
104129
});
105130
});

tests/rest-api-query-builder/rest-api-type-snapshot.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ describe("type snapshot", () => {
2323
.eq("nested.name", "value")
2424
)
2525
)
26+
.filterRelation("nestedList", () =>
27+
new RQBuilder<NestedModel>().contains("deepNestedList.deepProp", "test")
28+
)
2629
.populateDynamic("nested", "component.1", () =>
2730
new RQBuilder<NestedModel>().eq("id", "value")
2831
)
@@ -32,6 +35,11 @@ describe("type snapshot", () => {
3235
.populateRelation("nestedList", () =>
3336
new RQBuilder<NestedModel>().eq("name", "value2").field("name")
3437
)
38+
.populate("nestedListOptionalNullableUndefined")
39+
.publicationState("preview")
40+
.locale("en")
41+
.page(1)
42+
.pageSize(30)
3543
.build();
3644

3745
const assignedQuery: {
@@ -51,6 +59,11 @@ describe("type snapshot", () => {
5159
];
5260
}
5361
];
62+
},
63+
{
64+
nestedList: {
65+
$and: [{ deepNestedList: { deepProp: { $contains: "test" } } }];
66+
};
5467
}
5568
];
5669
};
@@ -67,7 +80,11 @@ describe("type snapshot", () => {
6780
fields: ["name"];
6881
filters: { $and: [{ name: { $eq: "value2" } }] };
6982
};
83+
nestedListOptionalNullableUndefined: { populate: "*" };
7084
};
85+
publicationState: "preview";
86+
locale: "en";
87+
pagination: { page: 1; pageSize: 30 };
7188
} = query;
7289

7390
expect(assignedQuery).toBeDefined();
@@ -90,6 +107,10 @@ describe("type snapshot", () => {
90107
expect(assignedQuery.filters.$and[1].$and[2].$and[1].nested.name.$eq).toBe(
91108
"value"
92109
);
110+
expect(
111+
assignedQuery.filters.$and[2].nestedList.$and[0].deepNestedList.deepProp
112+
.$contains
113+
).toEqual("test");
93114

94115
expect(
95116
assignedQuery.populate.nested.on["component.1"].filters.$and[0].id.$eq
@@ -102,5 +123,13 @@ describe("type snapshot", () => {
102123
expect(assignedQuery.populate.nestedList.filters.$and[0].name.$eq).toBe(
103124
"value2"
104125
);
126+
expect(
127+
assignedQuery.populate.nestedListOptionalNullableUndefined.populate
128+
).toBe("*");
129+
130+
expect(assignedQuery.publicationState).toEqual("preview");
131+
expect(assignedQuery.locale).toEqual("en");
132+
expect(assignedQuery.pagination.page).toEqual(1);
133+
expect(assignedQuery.pagination.pageSize).toEqual(30);
105134
});
106135
});

0 commit comments

Comments
 (0)