({
connection,
dataRequest,
itemsLimit,
items,
offset,
pagination,
paginationField,
})
| 153 | } |
| 154 | |
| 155 | async function previewDataRequest({ |
| 156 | connection, |
| 157 | dataRequest, |
| 158 | itemsLimit, |
| 159 | items, |
| 160 | offset, |
| 161 | pagination, |
| 162 | paginationField, |
| 163 | }) { |
| 164 | const savedConnection = await getSavedConnection(connection); |
| 165 | const limit = itemsLimit ? parseInt(itemsLimit, 10) : 0; |
| 166 | const policyContext = buildApiPolicyContext("api_request_test", savedConnection); |
| 167 | const tempUrl = `${savedConnection.getApiUrl(savedConnection)}${dataRequest.route || ""}`; |
| 168 | const queryParams = querystring.parse(tempUrl.split("?")[1]); |
| 169 | |
| 170 | let url = tempUrl; |
| 171 | if (url.indexOf("?") > -1) { |
| 172 | url = tempUrl.substring(0, tempUrl.indexOf("?")); |
| 173 | } |
| 174 | |
| 175 | const options = { |
| 176 | url, |
| 177 | method: dataRequest.method || "GET", |
| 178 | headers: {}, |
| 179 | qs: queryParams, |
| 180 | resolveWithFullResponse: true, |
| 181 | simple: false, |
| 182 | }; |
| 183 | |
| 184 | let headers = {}; |
| 185 | if (dataRequest.useGlobalHeaders) { |
| 186 | const globalHeaders = savedConnection.getHeaders(savedConnection); |
| 187 | for (const opt of globalHeaders) { |
| 188 | headers = Object.assign(opt, headers); |
| 189 | } |
| 190 | |
| 191 | if (dataRequest.headers) { |
| 192 | headers = Object.assign(dataRequest.headers, headers); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | options.headers = headers; |
| 197 | |
| 198 | if (dataRequest.body && dataRequest.method !== "GET") { |
| 199 | options.body = dataRequest.body; |
| 200 | options.headers["Content-Type"] = "application/json"; |
| 201 | } |
| 202 | |
| 203 | if (pagination) { |
| 204 | if ((options.url.indexOf(`?${items}=`) || options.url.indexOf(`&${items}=`)) |
| 205 | && (options.url.indexOf(`?${offset}=`) || options.url.indexOf(`&${offset}=`)) |
| 206 | ) { |
| 207 | return paginateRequests(dataRequest.template, { |
| 208 | options, |
| 209 | limit, |
| 210 | items, |
| 211 | offset, |
| 212 | paginationField, |
nothing calls this directly
no test coverage detected