-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.ts
53 lines (33 loc) · 1.34 KB
/
test.ts
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
/// <reference path="bundle.d.ts" />
import assert = require('assert');
import r = require('rethinkdb');
const options: r.ConnectOptions = {
host: 'localhost'
};
(async function () {
const conn = await r.connect(options);
const testDb = `test${Math.random().toString(36).substr(2)}`;
try {
const dbCreateResult = await r.dbCreate(testDb).run(conn);
assert.equal(dbCreateResult.dbs_created, 1);
conn.use(testDb);
const tableCreateResult = await r.tableCreate('Test').run(conn);
assert.equal(tableCreateResult.tables_created, 1);
assert.deepEqual(await r.tableList().run(conn), ['Test']);
const insertedNewId = await r.table('Test').insert({ hello: true }).run(conn);
assert.ok(Array.isArray(insertedNewId.generated_keys));
const insertedUseId = await r.table('Test').insert({ id: '123' }).run(conn);
assert.ok(typeof insertedUseId.generated_keys === 'undefined');
const result = await r.map([1, 2, 3], (v) => v.mul(10)).run(conn);
assert.deepEqual(result, [10, 20, 30]);
const tableDropResult = await r.tableDrop('Test').run(conn);
assert.equal(tableDropResult.tables_dropped, 1);
const dbDropResult = await r.dbDrop(testDb).run(conn);
assert.equal(dbDropResult.dbs_dropped, 1);
} catch (err) {
console.log(err);
process.exit(1);
} finally {
conn.close();
}
})();