Skip to content

Commit

Permalink
TESTS: add/adjust tests for duplicate post quiet rejection
Browse files Browse the repository at this point in the history
  • Loading branch information
makyen committed Sep 18, 2020
1 parent 0b738da commit cbdd662
Showing 1 changed file with 184 additions and 3 deletions.
187 changes: 184 additions & 3 deletions test/controllers/posts_controller_test.rb
Expand Up @@ -49,14 +49,17 @@ def setup
username: 'Undo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/1849664/undo',
why: 'Some why data',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.first.access_token
}

assert_response :success
end
end

test 'should reject recent duplicates from other instances' do
test 'should quietly reject recent duplicates from other instances as 200 Duplicate Report' do
post :create, params: {
post: {
title: 'blah blah blah',
Expand All @@ -65,6 +68,7 @@ def setup
username: 'Undo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/123',
why: 'Some why data',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.first.access_token
Expand All @@ -79,16 +83,85 @@ def setup
username: 'Undo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/123',
why: 'Some why data',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.last.access_token
}

assert_response :unprocessable_entity
assert_response(200, 'Duplicate Report')
end
end

test 'should quietly reject duplicate posts from same instance as 200 Duplicate Report' do
post :create, params: {
post: {
title: 'blah blah blah',
body: 'blah blah',
link: '//stackoverflow.com/questions/1234',
username: 'Undo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/123',
why: 'Some why data',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.first.access_token
}

assert_no_difference 'Post.count' do
post :create, params: {
post: {
title: 'blah blah blah',
body: 'blah blah',
link: '//stackoverflow.com/questions/1234',
username: 'Undo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/123',
why: 'Some why data',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.first.access_token
}

assert_response(200, 'Duplicate Report')
end
end

test 'should not reject near-duplicate posts with different title' do
post :create, params: {
post: {
title: 'blah blah blah',
body: 'blah blah',
link: '//stackoverflow.com/questions/1234',
username: 'Undo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/123',
why: 'Some why data',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.first.access_token
}

assert_difference 'Post.count' do
post :create, params: {
post: {
title: 'blah blah diff',
body: 'blah blah',
link: '//stackoverflow.com/questions/1234',
username: 'Undo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/123',
why: 'Some why data',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.first.access_token
}

assert_response(201, 'OK')
end
end

test 'should not reject duplicate posts from same instance' do
test 'should not reject near-duplicate posts with different body' do
post :create, params: {
post: {
title: 'blah blah blah',
Expand All @@ -97,6 +170,41 @@ def setup
username: 'Undo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/123',
why: 'Some why data',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.first.access_token
}

assert_difference 'Post.count' do
post :create, params: {
post: {
title: 'blah blah blah',
body: 'blah diff',
link: '//stackoverflow.com/questions/1234',
username: 'Undo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/123',
why: 'Some why data',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.first.access_token
}

assert_response(201, 'OK')
end
end

test 'should not reject near-duplicate posts with different username' do
post :create, params: {
post: {
title: 'blah blah blah',
body: 'blah blah',
link: '//stackoverflow.com/questions/1234',
username: 'Redo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/123',
why: 'Some why data',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.first.access_token
Expand All @@ -111,10 +219,81 @@ def setup
username: 'Undo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/123',
why: 'Some why data',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.first.access_token
}

assert_response(201, 'OK')
end
end

test 'should not reject near-duplicate posts with different why' do
post :create, params: {
post: {
title: 'blah blah blah',
body: 'blah blah',
link: '//stackoverflow.com/questions/1234',
username: 'Undo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/123',
why: 'Some why data',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.first.access_token
}

assert_difference 'Post.count' do
post :create, params: {
post: {
title: 'blah blah blah',
body: 'blah blah',
link: '//stackoverflow.com/questions/1234',
username: 'Undo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/123',
why: 'Some why diff',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.first.access_token
}

assert_response(201, 'OK')
end
end

test 'should not reject near-duplicate posts with different link' do
post :create, params: {
post: {
title: 'blah blah blah',
body: 'blah blah',
link: '//stackoverflow.com/questions/1234',
username: 'Undo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/123',
why: 'Some why data',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.first.access_token
}

assert_difference 'Post.count' do
post :create, params: {
post: {
title: 'blah blah blah',
body: 'blah blah',
link: '//stackoverflow.com/questions/1235',
username: 'Undo',
user_reputation: 101,
user_link: '//stackoverflow.com/users/123',
why: 'Some why data',
reasons: ['Bad keyword in body']
},
key: SmokeDetector.first.access_token
}

assert_response(201, 'OK')
end
end

Expand All @@ -132,6 +311,8 @@ def setup
},
key: SmokeDetector.first.access_token
}

assert_response :success
end
end

Expand Down

0 comments on commit cbdd662

Please sign in to comment.