-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
executable file
·68 lines (66 loc) · 2.45 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
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
const Setting = {
host: 'localhost',
port: 3306,
database: 'terraria',
user: 'terraria',
password: '04140906',
debug_mode: true
}
const Medoo = require('./medoo');
let assert = require('assert');
require('should');
var medoo;
describe('should setup without error', function () {
it('connection is not null', async function () {
medoo = new Medoo(Setting);
await medoo.setup();
assert(medoo.connection);
});
});
describe('Select', function () {
it('select all from Users and first item`s Username == endless', async function () {
assert(medoo.connection);
let result = await medoo.select('Users', "*");
assert(result);
assert(result[0]);
assert(result[0].Username);
result[0].Username.should.equal('endless');
});
it('select all from Users where Usergroup == default', async function () {
assert(medoo.connection);
let result = await medoo.select('Users', "*", { UserGroup: 'default' });
assert(result);
});
it('select all from Users where Usergroup != default', async function () {
assert(medoo.connection);
let result = await medoo.select('Users', "*", { "UserGroup[!]": 'default' });
assert(result);
});
it('select all from Users where ID > 10', async function () {
assert(medoo.connection);
let result = await medoo.select('Users', "*", { "ID[>]": 10 });
assert(result);
});
it('select all from Users where ID >= 10', async function () {
assert(medoo.connection);
let result = await medoo.select('Users', "*", { "ID[>=]": 10 });
assert(result);
});
it('select all from Users and format result', async function () {
assert(medoo.connection);
let result = await medoo.select('Users', ['ID',{user: ['Username', 'Usergroup']}]);
assert(result);
assert(result[0]);
assert(result[0].user);
result[0].ID.should.equal(1);
result[0].user.Username.should.equal('endless');
});
it('select all from Users left join tsCharacter where tsCharacter.Health >= 100', async function () {
assert(medoo.connection);
let result = await medoo.select('Users(u)', { "[>]tsCharacter(tc)": {"ID": "Account"}}, ['u.Username', 'tc.Health'], { "tc.Health[>]": 100 });
assert(result);
assert(result[0]);
assert(result[0].Username);
assert(result[0].Health>100);
});
});