|
1 | | -varconfig=require(__dirname+'/config.js'); |
2 | | -varr=require(__dirname+'/../lib')(config); |
3 | | -varassert=require('assert'); |
4 | | - |
5 | | -varconnection;// global connection |
6 | | -vardbName,tableName,docs; |
7 | | - |
8 | | - |
9 | | -functions4(){ |
10 | | -returnMath.floor((1+Math.random())*0x10000).toString(16).substring(1); |
11 | | -}; |
12 | | - |
13 | | -functionuuid(){ |
14 | | -returns4()+s4()+s4()+s4()+s4()+s4()+s4()+s4(); |
15 | | -} |
16 | | - |
17 | | -// Tests for callbacks |
18 | | -it("Create db",function(done){ |
19 | | -dbName=uuid(); |
20 | | - |
21 | | -r.dbCreate(dbName).run().then(function(result){ |
22 | | -assert.equal(result.dbs_created,1); |
23 | | -done(); |
24 | | -}).error(function(error){ |
25 | | -done(error); |
| 1 | +constpath=require('path') |
| 2 | +constconfig=require('./config.js') |
| 3 | +constrethinkdbdash=require(path.join(__dirname,'/../lib')) |
| 4 | +constassert=require('assert') |
| 5 | +const{uuid}=require(path.join(__dirname,'/util/common.js')) |
| 6 | +const{before, after, describe, it}=require('mocha') |
| 7 | + |
| 8 | +describe('stable',()=>{ |
| 9 | +letr,dbName,tableName,docs |
| 10 | + |
| 11 | +before(async()=>{ |
| 12 | +r=awaitrethinkdbdash(config) |
| 13 | +dbName=uuid() |
| 14 | +tableName=uuid() |
26 | 15 | }) |
27 | | -}) |
28 | 16 |
|
29 | | -it("Create table",function(done){ |
30 | | -tableName=uuid(); |
| 17 | +after(async()=>{ |
| 18 | +awaitr.getPoolMaster().drain() |
| 19 | +}) |
31 | 20 |
|
32 | | -r.db(dbName).tableCreate(tableName).run().then(function(result){ |
33 | | -assert.equal(result.tables_created,1); |
34 | | -done(); |
35 | | -}).error(function(error){ |
36 | | -done(error); |
| 21 | +// Tests for callbacks |
| 22 | +it('Create db',asyncfunction(){ |
| 23 | +constresult=awaitr.dbCreate(dbName).run() |
| 24 | +assert.equal(result.dbs_created,1) |
37 | 25 | }) |
38 | | -}) |
39 | 26 |
|
40 | | -it("Insert",function(done){ |
41 | | -r.db(dbName).table(tableName).insert([{name:"Michel",age:27},{name:"Sophie",age:23}]).run().then(function(result){ |
42 | | -assert.deepEqual(result.inserted,2); |
43 | | -done(); |
44 | | -}).error(function(error){ |
45 | | -done(error); |
| 27 | +it('Create table',asyncfunction(){ |
| 28 | +constresult=awaitr.db(dbName).tableCreate(tableName).run() |
| 29 | +assert.equal(result.tables_created,1) |
46 | 30 | }) |
47 | | -}) |
48 | 31 |
|
| 32 | +it('Insert',asyncfunction(){ |
| 33 | +constresult=awaitr.db(dbName).table(tableName).insert([{name:'Michel',age:27},{name:'Sophie',age:23}]).run() |
| 34 | +assert.deepEqual(result.inserted,2) |
| 35 | +}) |
49 | 36 |
|
50 | | -it("Table",function(done){ |
51 | | -r.db(dbName).table(tableName).run().then(function(result){ |
| 37 | +it('Table',asyncfunction(){ |
| 38 | +constresult=docs=awaitr.db(dbName).table(tableName).run() |
52 | 39 | assert(result.length,2) |
53 | | -docs=result; |
54 | | -done(); |
55 | | -}).error(function(error){ |
56 | | -done(error); |
57 | 40 | }) |
58 | | -}) |
59 | 41 |
|
60 | | -it("get",function(done){ |
61 | | -r.db(dbName).table(tableName).get(docs[0].id).run().then(function(result){ |
| 42 | +it('get',asyncfunction(){ |
| 43 | +constresult=awaitr.db(dbName).table(tableName).get(docs[0].id).run() |
62 | 44 | assert.deepEqual(result,docs[0]) |
63 | | -done(); |
64 | | -}).error(function(error){ |
65 | | -done(error); |
66 | 45 | }) |
67 | | -}) |
68 | 46 |
|
69 | | -it("datum",function(done){ |
70 | | -r.expr({foo:"bar"}).run().then(function(result){ |
71 | | -assert.deepEqual(result,{foo:"bar"}) |
72 | | -done(); |
73 | | -}).error(function(error){ |
74 | | -done(error); |
| 47 | +it('datum',asyncfunction(){ |
| 48 | +constresult=awaitr.expr({foo:'bar'}).run() |
| 49 | +assert.deepEqual(result,{foo:'bar'}) |
75 | 50 | }) |
76 | | -}) |
77 | 51 |
|
78 | | -it("date",function(done){ |
79 | | -r.now().run().then(function(result){ |
80 | | -assert(resultinstanceofDate) |
81 | | -done(); |
82 | | -}).error(function(error){ |
83 | | -done(error); |
| 52 | +it('date',asyncfunction(){ |
| 53 | +constresult=awaitr.now().run() |
| 54 | +assert(resultinstanceofDate) |
84 | 55 | }) |
85 | 56 | }) |
86 | | - |