Skip to content

Commit dbe7104

Browse files
authored
refactor app data e2e (#372)
* refactor app_data_e2e * .
1 parent 4a6b51e commit dbe7104

File tree

3 files changed

+122
-126
lines changed

3 files changed

+122
-126
lines changed
Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,70 @@
1+
import axios from 'axios'
12
import { Item } from '@wix-velo/velo-external-db-types'
3+
import { dataSpi } from '@wix-velo/velo-external-db-core'
4+
import { streamToArray } from '@wix-velo/test-commons'
25

3-
const axios = require('axios').create({
6+
const axiosInstance = axios.create({
47
baseURL: 'http://localhost:8080'
58
})
69

7-
export const givenItems = async(items: Item[], collectionName: string, auth: any) => await axios.post('/data/insert/bulk', { collectionName: collectionName, items: items }, auth)
10+
export const insertRequest = (collectionName: string, items: Item[], overwriteExisting: boolean): dataSpi.InsertRequest => ({
11+
collectionId: collectionName,
12+
items: items,
13+
overwriteExisting,
14+
options: {
15+
consistentRead: false,
16+
appOptions: {},
17+
}
18+
})
19+
20+
export const updateRequest = (collectionName: string, items: Item[]): dataSpi.UpdateRequest => ({
21+
collectionId: collectionName,
22+
items: items,
23+
options: {
24+
consistentRead: false,
25+
appOptions: {},
26+
}
27+
})
28+
29+
export const countRequest = (collectionName: string): dataSpi.CountRequest => ({
30+
collectionId: collectionName,
31+
filter: '',
32+
options: {
33+
consistentRead: false,
34+
appOptions: {},
35+
},
36+
})
37+
38+
export const queryRequest = (collectionName: string, sort: dataSpi.Sorting[], fields: string[], filter?: dataSpi.Filter): dataSpi.QueryRequest => ({
39+
collectionId: collectionName,
40+
query: {
41+
filter: filter ?? '',
42+
sort: sort,
43+
fields: fields,
44+
fieldsets: undefined,
45+
paging: {
46+
limit: 25,
47+
offset: 0,
48+
},
49+
cursorPaging: null
50+
},
51+
includeReferencedItems: [],
52+
options: {
53+
consistentRead: false,
54+
appOptions: {},
55+
},
56+
omitTotalCount: false
57+
})
58+
59+
60+
export const queryCollectionAsArray = (collectionName: string, sort: dataSpi.Sorting[], fields: string[], auth: any, filter?: dataSpi.Filter) =>
61+
axiosInstance.post('/data/query',
62+
queryRequest(collectionName, sort, fields, filter), { responseType: 'stream', transformRequest: auth.transformRequest })
63+
.then(response => streamToArray(response.data))
64+
65+
66+
export const pagingMetadata = (total: number, count: number): dataSpi.QueryResponsePart => ({ pagingMetadata: { count: count, offset: 0, total: total, tooManyToCount: false } })
67+
868

9-
export const expectAllDataIn = async(collectionName: string, auth: any) => (await axios.post('/data/find', { collectionName: collectionName, filter: '', sort: '', skip: 0, limit: 25 }, auth)).data
69+
export const givenItems = async(items: Item[], collectionName: string, auth: any) =>
70+
await axiosInstance.post('/data/insert', insertRequest(collectionName, items, false), { responseType: 'stream', transformRequest: auth.transformRequest })

0 commit comments

Comments
 (0)