-
Notifications
You must be signed in to change notification settings - Fork 8
/
likes.js
126 lines (97 loc) · 5.07 KB
/
likes.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import {
getInfoFromLogs,
likes,
setupParatiiContracts
} from './utils.js'
contract('Likes', function (accounts) {
let videoId = '1234'
let tx
// before(function () {
// setupParatiiContracts()
// })
it('like video should work as expected', async function () {
await setupParatiiContracts()
assert.equal(await likes.userLikesVideo(accounts[1], videoId).valueOf(), false)
assert.equal(await likes.userDislikesVideo(accounts[1], videoId).valueOf(), false)
assert.equal(Number(await likes.vidLikes(videoId)), 0)
assert.equal(Number(await likes.userLikes(accounts[1])), 0)
tx = await likes.likeVideo(videoId, true, {from: accounts[1]})
assert.equal(getInfoFromLogs(tx, '_address', 'LogLikeVideo'), accounts[1])
assert.equal(getInfoFromLogs(tx, '_videoId'), videoId)
assert.equal(getInfoFromLogs(tx, '_liked'), true)
assert.equal(await likes.userLikesVideo(accounts[1], videoId), true)
assert.equal(await likes.userDislikesVideo(accounts[1], videoId), false)
assert.equal(await likes.userLikes(accounts[1]), 1)
assert.equal(Number(await likes.vidLikes(videoId)), 1)
assert.equal(Number(await likes.vidDislikes(videoId)), 0)
assert.equal(Number(await likes.userDislikes(videoId)), 0)
})
it('dislike video should work as expected', async function () {
await setupParatiiContracts()
tx = await likes.likeVideo(videoId, false, {from: accounts[1]})
assert.equal(getInfoFromLogs(tx, '_address'), accounts[1])
assert.equal(getInfoFromLogs(tx, '_videoId'), videoId)
assert.equal(getInfoFromLogs(tx, '_liked'), false)
assert.equal(await likes.userLikesVideo(accounts[1], videoId), false)
assert.equal(await likes.userDislikesVideo(accounts[1], videoId), true)
assert.equal(await likes.userLikes(accounts[1]), 0)
assert.equal(Number(await likes.userDislikes(accounts[1])), 1)
assert.equal(Number(await likes.vidLikes(videoId)), 0)
assert.equal(Number(await likes.vidDislikes(videoId)), 1)
})
it('dislike video should override like', async function () {
await setupParatiiContracts()
await likes.likeVideo(videoId, true, {from: accounts[1]})
await likes.likeVideo(videoId, false, {from: accounts[1]})
assert.equal(await likes.userLikesVideo(accounts[1], videoId), false)
assert.equal(await likes.userDislikesVideo(accounts[1], videoId), true)
assert.equal(Number(await likes.userLikes(accounts[1])), 0)
assert.equal(Number(await likes.userDislikes(accounts[1])), 1)
assert.equal(Number(await likes.vidLikes(videoId)), 0)
assert.equal(Number(await likes.vidDislikes(videoId)), 1)
})
it('like video should override dislike', async function () {
await setupParatiiContracts()
await likes.likeVideo(videoId, false, {from: accounts[1]})
await likes.likeVideo(videoId, true, {from: accounts[1]})
assert.equal(await likes.userLikesVideo(accounts[1], videoId), true)
assert.equal(await likes.userDislikesVideo(accounts[1], videoId), false)
assert.equal(Number(await likes.userLikes(accounts[1])), 1)
assert.equal(Number(await likes.userDislikes(accounts[1])), 0)
assert.equal(Number(await likes.vidLikes(videoId)), 1)
assert.equal(Number(await likes.vidDislikes(videoId)), 0)
})
it('like video should be cumulative', async function () {
await setupParatiiContracts()
await likes.likeVideo(videoId, true, {from: accounts[1]})
await likes.likeVideo(videoId, true, {from: accounts[2]})
assert.equal(await likes.userLikesVideo(accounts[1], videoId), true)
assert.equal(await likes.userDislikesVideo(accounts[1], videoId), false)
assert.equal(await likes.userLikesVideo(accounts[2], videoId), true)
assert.equal(await likes.userDislikesVideo(accounts[2], videoId), false)
assert.equal(Number(await likes.userLikes(accounts[2])), 1)
assert.equal(Number(await likes.userDislikes(accounts[2])), 0)
assert.equal(Number(await likes.vidLikes(videoId)), 2)
assert.equal(Number(await likes.vidDislikes(videoId)), 0)
})
it('dislike video should be cumulative', async function () {
await setupParatiiContracts()
await likes.likeVideo(videoId, false, {from: accounts[1]})
await likes.likeVideo(videoId, false, {from: accounts[2]})
assert.equal(await likes.userLikesVideo(accounts[1], videoId), false)
assert.equal(await likes.userDislikesVideo(accounts[1], videoId), true)
assert.equal(await likes.userLikesVideo(accounts[2], videoId), false)
assert.equal(await likes.userDislikesVideo(accounts[2], videoId), true)
assert.equal(Number(await likes.userLikes(accounts[2])), 0)
assert.equal(Number(await likes.userDislikes(accounts[2])), 1)
assert.equal(Number(await likes.vidLikes(videoId)), 0)
assert.equal(Number(await likes.vidDislikes(videoId)), 2)
})
it('dislikes and likes can coexist', async function () {
await setupParatiiContracts()
await likes.likeVideo(videoId, false, {from: accounts[1]})
await likes.likeVideo(videoId, true, {from: accounts[2]})
assert.equal(Number(await likes.vidLikes(videoId)), 1)
assert.equal(Number(await likes.vidDislikes(videoId)), 1)
})
})