-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathdb.strings.js
73 lines (64 loc) · 1.76 KB
/
db.strings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const chai = require('chai')
const expect = chai.expect
const request = require('supertest')
const testutils = require('./testutils')
const { app, api } = testutils
const collectionNames = ['memorytest', 'filetest']
if (process.env.TEST_MONGO) {
collectionNames.push('mongotest')
}
if (process.env.TEST_POSTGRES) {
collectionNames.push('postgrestest')
}
collectionNames.forEach(function (collection) {
describe(`${collection} string ids`, function () {
let db
const collectionName = collection + '2'
before(async function () {
const coll = {
_id: collectionName,
schema: {
type: 'object',
additionalProperties: false,
properties: {
_id: {
type: 'string'
},
title: {
type: 'string'
},
}
},
storage: collection.replace('test', ''),
documentsHaveOwners: false,
plainStringIds: true
}
const token = await testutils.getUserWithPermissions(api, 'collection: create')
await request(app)
.post('/collection')
.set('x-access-token', token)
.send(coll)
.expect(200)
db = api.db[collectionName]
})
let id
const id2 = 'short_custom_id'
it('create without id', async function () {
id = await db.create({
title: 'first',
data: { field: '123' },
arr: [{ color: 'red', subarray: [{ v: 'abc' }] }],
})
expect(id.length).to.be.greaterThan(6)
})
it('create with id', async function () {
const id = await db.create({
_id: id2,
title: 'second',
arr: [ { color: 'blue', num: 1337 }],
data: { nestedArr: ['abc'] }
})
expect(id).to.equal(id2)
})
})
})