-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
33 lines (31 loc) · 1.08 KB
/
test.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
"use strict"
const { jrGQL } = require('jrgql')
const { MongoDbDriver } = require('./MongoDbDriver')
const _ = require('underscore')
;(async () => {
const exampleDbContent = require('jrgql').examples["usergroup"]
const db = new MongoDbDriver()
await db.connect()
await db.init(exampleDbContent)
const ql = new jrGQL(db)
for (const test of exampleDbContent.tests) {
const results = await ql.query(test.rootType, test.input)
if (test.title == 'Action') {
console.log(`Test "${test.title}" is skipped.`)
continue
}
if (test.title == 'Mutation') {
test.output.forEach(o => delete o[0][db.idMember])
results.forEach(o => delete o[0][db.idMember])
}
if (_.isEqual(results, test.output)) {
console.log(`Test "${test.title}" is successful.`)
} else {
console.log(`Test "${test.title}" failed.`)
console.log(`Expected: ${JSON.stringify(test.output, null, " ")}`)
console.log(`Results: ${JSON.stringify(results, null, " ")}`)
console.log(`-----------------------------------`)
}
}
await db.disconnect()
})()