-
Notifications
You must be signed in to change notification settings - Fork 10
/
crud.js
53 lines (47 loc) · 1.22 KB
/
crud.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
const Crud = artifacts.require('Crud');
contract('Crud', () => {
let crud;
beforeEach(async () => {
crud = await Crud.deployed();
});
it('Should create a new user', async () => {
await crud.create('Frank');
const user = await crud.read(1);
assert(user[0].toNumber() === 1);
assert(user[1] === 'Frank');
});
it('Should update an existing user', async () => {
await crud.update(1, 'Frankk');
const user = await crud.read(1);
assert(user[0].toNumber() === 1);
assert(user[1] === 'Frankk');
});
it('Should NOT update a non-existing user', async () => {
try {
await crud.update(2, 'Frankk');
} catch(e) {
assert(e.message.includes('User does not exist'));
return;
}
assert(false);
});
it('Should destroy an existing user', async () => {
await crud.destroy(1);
try {
const user = await crud.read(1);
} catch(e) {
assert(e.message.includes('User does not exist'));
return;
}
assert(false);
});
it('Should NOT destroy a non-existing user', async () => {
try {
await crud.destroy(10);
} catch(e) {
assert(e.message.includes('User does not exist'));
return;
}
assert(false);
});
});