You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(type): add type aware getAll function that works with ISbLinksParams
Problem:
- Developers may need to `getAll` when getting an unpaginated response from `cdn/links`
- Currently when calling `cdn/links` with ISbLinksParams results with compile time error when using ISbLinksParams specific params like: include_dates
Solution:
- Make `getAll` function generic to make it type aware of the intention of the developer
- Updated the function to not allow developers to modify the number of round trips for fetching all results
- Updated unit tests and e2e tests
Closes: storyblok#944
it('getAll(\'cdn/stories\') should return all stories',async()=>{
89
-
constresult=awaitclient.getAll('cdn/stories',{});
90
-
expect(result.length).toBeGreaterThan(0);
91
-
});
88
+
describe('getAll(\'cdn/stories\')',()=>{
89
+
it('should not compile if any of `per_page`, or `page` is passed on to the param',async()=>{
90
+
constresult=awaitclient.getAll('cdn/stories',{
91
+
// @ts-expect-error the client when calling get all is fully aware that all results will be loaded in memory. This type check assertion ensures that it is not upto the client on how many round trips StoryblokClient will make in order to get all result.
92
+
per_page: 20,
93
+
page: 1,
94
+
});
95
+
expect(result.length).toBeGreaterThan(0);
96
+
});
92
97
93
-
it('getAll(\'cdn/stories\') should return all stories with filtered results',async()=>{
94
-
constresult=awaitclient.getAll('cdn/stories',{
95
-
starts_with: 'testcontent-0',
98
+
it('should return all stories',async()=>{
99
+
constresult=awaitclient.getAll('cdn/stories');
100
+
expect(result.length).toBeGreaterThan(0);
96
101
});
97
-
expect(result.length).toBe(1);
98
-
});
99
102
100
-
it('getAll(\'cdn/stories\', filter_query: { __or: [{ category: { any_in_array: \'Category 1\' } }, { category: { any_in_array: \'Category 2\' } }]}) should return all stories with the specific filter applied',async()=>{
101
-
constresult=awaitclient.getAll('cdn/stories',{
102
-
filter_query: {
103
-
__or: [
104
-
{category: {any_in_array: 'Category 1'}},
105
-
{category: {any_in_array: 'Category 2'}},
106
-
],
107
-
},
103
+
it('should return all stories with filtered results',async()=>{
104
+
constresult=awaitclient.getAll('cdn/stories',{
105
+
starts_with: 'testcontent-0',
106
+
});
107
+
expect(result.length).toBe(1);
108
108
});
109
-
expect(result.length).toBeGreaterThan(0);
110
-
});
111
109
112
-
it('getAll(\'cdn/stories\', {by_slugs: \'folder/*\'}) should return all stories with the specific filter applied',async()=>{
113
-
constresult=awaitclient.getAll('cdn/stories',{
114
-
by_slugs: 'folder/*',
110
+
it('should return all stories with the specific filter applied',async()=>{
111
+
constresult=awaitclient.getAll('cdn/stories',{
112
+
filter_query: {
113
+
__or: [
114
+
{category: {any_in_array: 'Category 1'}},
115
+
{category: {any_in_array: 'Category 2'}},
116
+
],
117
+
},
118
+
});
119
+
expect(result.length).toBeGreaterThan(0);
120
+
});
121
+
122
+
it('should return all stories with the specific filter applied',async()=>{
123
+
constresult=awaitclient.getAll('cdn/stories',{
124
+
by_slugs: 'folder/*',
125
+
});
126
+
expect(result.length).toBeGreaterThan(0);
115
127
});
116
-
expect(result.length).toBeGreaterThan(0);
117
128
});
118
129
119
-
it('getAll(\'cdn/links\') should return all links',async()=>{
120
-
constresult=awaitclient.getAll('cdn/links',{});
121
-
expect(result.length).toBeGreaterThan(0);
130
+
describe('getAll(\'cdn/links\')',()=>{
131
+
it('should not compile if any of `per_page`, `paginated` or `page` is passed on to the param',async()=>{
132
+
constresult=awaitclient.getAll('cdn/links',{
133
+
// @ts-expect-error the client when calling get all is fully aware that all results will be loaded in memory. This type check assertion ensures that it is not upto the client on how many round trips StoryblokClient will make in order to get all result.
134
+
per_page: 20,
135
+
paginated: 1,
136
+
page: 1,
137
+
});
138
+
expect(result.length).toBeGreaterThan(0);
139
+
});
140
+
141
+
it('should return all links',async()=>{
142
+
constresult=awaitclient.getAll('cdn/links');
143
+
expect(result.length).toBeGreaterThan(0);
144
+
});
145
+
146
+
it('should return key wise links to be flattened out to an array of ISbLink shape',async()=>{
0 commit comments