Skip to content

Commit fb88a83

Browse files
ci: delete more orphaned resources from e2e tests (#9580)
* ci: delete more orphaned resources from e2e tests We were not getting all pages of results from the backend. * Remove rendundant type param * fix eslint error
1 parent 384a425 commit fb88a83

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

tools/e2e/common.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,26 +113,42 @@ const apiFetchResponse = async (
113113
}
114114
};
115115

116-
const apiFetch = async (
116+
async function apiFetch(
117117
path: string,
118118
init = { method: "GET" },
119119
failSilently = false,
120120
queryParams = {}
121-
) => {
122-
const response = await apiFetchResponse(
123-
path,
124-
init,
125-
failSilently,
126-
queryParams
127-
);
121+
) {
122+
let page = 1;
123+
let result: unknown[] = [];
124+
// eslint-disable-next-line no-constant-condition
125+
while (true) {
126+
const response = await apiFetchResponse(path, init, failSilently, {
127+
...queryParams,
128+
page,
129+
});
128130

129-
if (!response || response.ok === false) {
130-
return false;
131-
}
131+
if (!response || response.ok === false) {
132+
return false;
133+
}
132134

133-
const json = (await response.json()) as ApiSuccessBody;
134-
return json.result;
135-
};
135+
const json = (await response.json()) as ApiSuccessBody;
136+
if ("result_info" in json && Array.isArray(json.result)) {
137+
const result_info = json.result_info as {
138+
page: number;
139+
count: number;
140+
};
141+
if (result_info.count === 0) {
142+
return result;
143+
}
144+
result = [...result, ...json.result];
145+
console.log(result_info, result_info.page, result_info.count);
146+
page = result_info.page + 1;
147+
} else {
148+
return json.result;
149+
}
150+
}
151+
}
136152

137153
export const listTmpE2EProjects = async () => {
138154
const pageSize = 10;

0 commit comments

Comments
 (0)