Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

74 auth via email link gem passwordless #75

Merged
merged 28 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bc15fcc
add passwordless
yshmarov Nov 8, 2022
d2e34ba
add gem letter-opener
yshmarov Nov 8, 2022
973942c
add passwordless views
yshmarov Nov 8, 2022
333b627
make sign in work
yshmarov Nov 8, 2022
0775293
users#show, basic views work
yshmarov Nov 8, 2022
bb9897a
Update new.html.erb
yshmarov Nov 8, 2022
6830e43
no more need to load insta user in session
yshmarov Nov 8, 2022
c9c0bac
insta user belongs to user
yshmarov Nov 8, 2022
a56e780
add passwordless initializer
yshmarov Nov 8, 2022
babb292
prepare for sending emails in production
yshmarov Nov 8, 2022
2ea5c44
require user for users controller, i18n
yshmarov Nov 8, 2022
37d2719
Update new.html.erb
yshmarov Nov 8, 2022
fcc20b6
associate insta user with user
yshmarov Nov 8, 2022
a6e15ff
display insta users of a user
yshmarov Nov 8, 2022
a88413a
no need for user partial in insta users index
yshmarov Nov 8, 2022
479b9d7
validation for import action
yshmarov Nov 8, 2022
074b6c0
move import action from ig_posts to ig_user
yshmarov Nov 8, 2022
0b4bcbb
Update show.html.erb
yshmarov Nov 8, 2022
edb31c7
Update show.html.erb
yshmarov Nov 8, 2022
0e9acd5
fix import
yshmarov Nov 9, 2022
52e1237
depreciate insta_user#show in favour of insta posts#index
yshmarov Nov 9, 2022
e9f56ef
Update new.html.erb
yshmarov Nov 9, 2022
3dafeba
after connect insta account redirect to user path
yshmarov Nov 9, 2022
32e2b91
Update users_controller.rb
yshmarov Nov 9, 2022
5e62487
annotate routes
yshmarov Nov 9, 2022
02573bb
update tests
yshmarov Nov 9, 2022
18c48da
update AWS SES creds for prod
yshmarov Nov 9, 2022
2fec4b0
Update user.rb
yshmarov Nov 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update tests
  • Loading branch information
yshmarov committed Nov 9, 2022
commit 02573bbbd44cb06647f07f4909b719da54bd9bc6
63 changes: 10 additions & 53 deletions test/integration/insta_posts_test.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
require 'test_helper'

# rubocop:disable Metrics/MethodLength, Layout/LineLength
# rubocop:disable Layout/LineLength
class InstaPostsTest < ActionDispatch::IntegrationTest
def setup
@user = InstaUser.create(username: 'yaro_the_slav', remote_id: SecureRandom.random_number(9999))
@user.insta_access_tokens.create
@insta_user = InstaUser.create(username: 'yaro_the_slav', remote_id: SecureRandom.random_number(9999))
end

test 'index' do
post1 = InstaPost.create(insta_user: @user, remote_id: SecureRandom.random_number(9999), timestamp: Time.zone.now,
post1 = InstaPost.create(insta_user: @insta_user, remote_id: SecureRandom.random_number(9999), timestamp: Time.zone.now,
caption: 'Post by this user')
user2 = InstaUser.create(username: 'za.yuliia', remote_id: SecureRandom.random_number(9999))
post2 = InstaPost.create(insta_user: user2, remote_id: SecureRandom.random_number(9999), timestamp: Time.zone.now,
caption: 'Post by other user')
ProcessCaptionService.new(post1).call
ProcessCaptionService.new(post2).call

get insta_user_posts_url(@user)
get insta_user_posts_url(@insta_user)

assert_response :success

Expand All @@ -25,65 +24,23 @@ def setup
end

test 'show' do
@post = InstaPost.create(insta_user: @user, remote_id: SecureRandom.random_number(9999), timestamp: Time.zone.now, caption: 'some text')
get insta_user_post_url(@user, @post)
@post = InstaPost.create(insta_user: @insta_user, remote_id: SecureRandom.random_number(9999), timestamp: Time.zone.now, caption: 'some text')
get insta_user_post_url(@insta_user, @post)
assert_response :success
assert_no_match 'More posts from', @response.body
assert_no_match 'some text', response.body

# when user has other posts, displays "more posts from"
InstaPost.create(insta_user: @user, remote_id: SecureRandom.random_number(9999), timestamp: Time.zone.now, media_url: 'itos-logo.png')
get insta_user_post_url(@user, @post)
InstaPost.create(insta_user: @insta_user, remote_id: SecureRandom.random_number(9999), timestamp: Time.zone.now, media_url: 'itos-logo.png')
get insta_user_post_url(@insta_user, @post)
assert_response :success
assert_match 'More posts from', @response.body

# displays body if ProcessCaptionService was run
ProcessCaptionService.new(@post).call
get insta_user_post_url(@user, @post)
get insta_user_post_url(@insta_user, @post)
assert_response :success
assert_match 'some text', response.body
end

test 'import' do
stub_request(:get, 'https://graph.instagram.com/me/media?access_token&fields=id,caption,media_type,media_url,permalink,thumbnail_url,timestamp,username')
.to_return(status: 200, body: response_body.to_json, headers: {})

post import_insta_user_path(@user)
assert_response :redirect

assert_redirected_to insta_user_posts_path(InstaUser.last)

follow_redirect!
assert_response :success
assert_match 'Run forest', @response.body
end

private

def response_body
{ 'data' =>
[{ 'id' => '179275846',
'caption' => 'Run forest run 🏃‍♂️ 🐕',
'media_type' => 'IMAGE',
'media_url' =>
'https://scontent.cdninstagram.com/v/t51.29350-15/3115039.jpg?_nc_cat=101&ccb=1-7&_nc_sid=8ae9d6&_nc_ohc=E2D66GZ',
'permalink' => 'https://www.instagram.com/p/CjqhZZ/',
'timestamp' => '2022-10-13T18:44:12+0000',
'username' => 'yaro_the_slav' },
{ 'id' => '1791585433',
'caption' => 'Piadina - something between a Calzone and a Taco. Yum yum!😋',
'media_type' => 'IMAGE',
'media_url' =>
'https://scontent.cdninstagram.com/v/t51.29350-15/26127.jpg?_nc_cat=106&ccb=1-7&_nc_sid=8ae9d6&_nc_ohc=fQNiTMukNTQ',
'permalink' => 'https://www.instagram.com/p/CWx4Xqh/',
'timestamp' => '2021-11-27T12:31:30+0000',
'username' => 'yaro_the_slav' }],
'paging' =>
{ 'cursors' =>
{ 'before' => 'ABC',
'after' => 'XYZ' },
'next' =>
'https://graph.instagram.com/v15.0/12345/media?access_token=IGQVJY&fields=id%2Ccaption%2Cmedia_type%2Cmedia_url%2Cpermalink%2Cthumbnail_url%2Ctimestamp%2Cusername&limit=25&after=DEF' } }
end
end
# rubocop:enable Metrics/MethodLength, Layout/LineLength
# rubocop:enable Layout/LineLength
56 changes: 54 additions & 2 deletions test/integration/insta_users_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# bin/rails generate integration_test sessions
require 'test_helper'

# rubocop:disable Metrics/MethodLength, Layout/LineLength
class InstaUsersTest < ActionDispatch::IntegrationTest
def setup
@user = InstaUser.create(username: 'yaro_the_slav', remote_id: '123')
@user = users(:one)
@insta_user = InstaUser.create(username: 'yaro_the_slav', remote_id: '123', user: @user)
@insta_user.insta_access_tokens.create
end

test 'index' do
Expand All @@ -12,7 +15,56 @@ def setup
end

test 'show' do
get insta_user_url(@user)
get insta_user_url(@insta_user)
assert_response :redirect
assert_redirected_to insta_user_posts_path(@insta_user)

follow_redirect!
assert_response :success
assert_match @insta_user.username, @response.body
end

test 'import' do
passwordless_sign_in(@user)

stub_request(:get, 'https://graph.instagram.com/me/media?access_token&fields=id,caption,media_type,media_url,permalink,thumbnail_url,timestamp,username')
.to_return(status: 200, body: response_body.to_json, headers: {})

post import_insta_user_path(@insta_user)
assert_response :redirect
assert_redirected_to insta_user_posts_path(InstaUser.last)

follow_redirect!
assert_response :success
assert_match 'Run forest', @response.body
end

private

def response_body
{ 'data' =>
[{ 'id' => '179275846',
'caption' => 'Run forest run 🏃‍♂️ 🐕',
'media_type' => 'IMAGE',
'media_url' =>
'https://scontent.cdninstagram.com/v/t51.29350-15/3115039.jpg?_nc_cat=101&ccb=1-7&_nc_sid=8ae9d6&_nc_ohc=E2D66GZ',
'permalink' => 'https://www.instagram.com/p/CjqhZZ/',
'timestamp' => '2022-10-13T18:44:12+0000',
'username' => 'yaro_the_slav' },
{ 'id' => '1791585433',
'caption' => 'Piadina - something between a Calzone and a Taco. Yum yum!😋',
'media_type' => 'IMAGE',
'media_url' =>
'https://scontent.cdninstagram.com/v/t51.29350-15/26127.jpg?_nc_cat=106&ccb=1-7&_nc_sid=8ae9d6&_nc_ohc=fQNiTMukNTQ',
'permalink' => 'https://www.instagram.com/p/CWx4Xqh/',
'timestamp' => '2021-11-27T12:31:30+0000',
'username' => 'yaro_the_slav' }],
'paging' =>
{ 'cursors' =>
{ 'before' => 'ABC',
'after' => 'XYZ' },
'next' =>
'https://graph.instagram.com/v15.0/12345/media?access_token=IGQVJY&fields=id%2Ccaption%2Cmedia_type%2Cmedia_url%2Cpermalink%2Cthumbnail_url%2Ctimestamp%2Cusername&limit=25&after=DEF' } }
end
end
# rubocop:enable Metrics/MethodLength, Layout/LineLength
12 changes: 10 additions & 2 deletions test/integration/instagram_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@

# rubocop:disable Style/NumericLiterals, Layout/LineLength
class InstagramTest < ActionDispatch::IntegrationTest
def setup
@user = users(:one)
end

test 'authorize' do
get instagram_authorize_url
assert_response :redirect
end

test 'callback' do
passwordless_sign_in(@user)

stub_ask_short_lived_access_token
stub_ask_long_lived_access_token
stub_ask_user_profile

get instagram_callback_url(code: 'callbackcode123')
assert_response :redirect
assert_redirected_to insta_user_path(InstaUser.last.id)
assert_redirected_to user_path

follow_redirect!
assert_response :success
assert_match "Click 'Import' to continue!", @response.body
assert_match 'Connect an Instagram account', @response.body
assert_match 'posts detected', @response.body
assert_match '305', @response.body
end

private
Expand Down
8 changes: 0 additions & 8 deletions test/integration/sessions_test.rb

This file was deleted.

1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require_relative '../config/environment'
require 'rails/test_help'
require 'webmock/minitest'
require 'passwordless/test_helpers'

class ActiveSupport::TestCase
# Run tests in parallel with specified workers
Expand Down