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
|
# frozen_string_literal: true
require 'test_helper'
class Api::V2::InteractionsControllerTest < ActionController::TestCase
setup do
@image = create(:post)
@request.cookies['_ses'] = 'c1836832948'
@user = create(:user)
sign_in @user
end
test 'upvoting should upvote an image' do
assert_equal 0, @image.upvotes_count
put :vote, params: { id: @image.id, value: 'up' }
@image.reload
assert_equal 1, @image.upvotes_count
assert_equal 0, @image.downvotes_count
assert_equal 0, @image.faves_count
end
test 'downvoting should downvote an image' do
assert_equal 0, @image.downvotes_count
put :vote, params: { id: @image.id, value: 'down' }
@image.reload
assert_equal 1, @image.downvotes_count
assert_equal 0, @image.upvotes_count
assert_equal 0, @image.faves_count
end
test 'can remove a vote' do
@image.votes.create(user: @user, up: true)
assert_equal 1, @image.upvotes_count
put :vote, params: { id: @image.id, value: 'false' }
@image.reload
assert_equal 0, @image.upvotes_count
end
test 'faving should add an upvote' do
assert_equal 0, @image.faves_count
put :fave, params: { id: @image.id, value: 'true' }
@image.reload
assert_equal 1, @image.faves_count
assert_equal 1, @image.upvotes_count
end
test 'unfaving should leave the upvote in place' do
@image.votes.create(user: @user, up: true)
@image.faves.create(user: @user)
assert_equal 1, @image.faves_count
assert_equal 1, @image.upvotes_count
put :fave, params: { id: @image.id, value: 'false' }
@image.reload
assert_equal 0, @image.faves_count
assert_equal 1, @image.upvotes_count
end
end
|