mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 03:37:56 +01:00
Add default OAuths (#259)
This commit is contained in:
committed by
GitHub
parent
0828c9c879
commit
653e139a9e
@@ -1,7 +1,7 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe OAuthsHelper, type: :helper do
|
||||
context 'query_path_from_hash method' do
|
||||
context 'query_path_from_object method' do
|
||||
it 'queries a path from hash' do
|
||||
email = "admin@example.com"
|
||||
name = "Admin"
|
||||
@@ -23,14 +23,40 @@ RSpec.describe OAuthsHelper, type: :helper do
|
||||
name_path = "info.name"
|
||||
surname_path = "info.additional_info.surnames[2][0].surname"
|
||||
|
||||
expect(helper.query_path_from_hash(hash, name_path)).to eq(name)
|
||||
expect(helper.query_path_from_hash(hash, email_path)).to eq(email)
|
||||
expect(helper.query_path_from_hash(hash, surname_path)).to eq(surname)
|
||||
expect(helper.query_path_from_object(hash, name_path)).to eq(name)
|
||||
expect(helper.query_path_from_object(hash, email_path)).to eq(email)
|
||||
expect(helper.query_path_from_object(hash, surname_path)).to eq(surname)
|
||||
end
|
||||
|
||||
it 'queries a path from array' do
|
||||
email1 = "admin1@example.com"
|
||||
email2 = "admin2@example.com"
|
||||
address = "Address1"
|
||||
|
||||
array = [
|
||||
{
|
||||
"email" => email1,
|
||||
},
|
||||
{
|
||||
"email" => email2,
|
||||
"additional_info" => {
|
||||
"addresses" => [{ "name" => address }]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
email1_path = "[0].email"
|
||||
email2_path = "[1].email"
|
||||
address_path = "[1].additional_info.addresses[0].name"
|
||||
|
||||
expect(helper.query_path_from_object(array, email1_path)).to eq(email1)
|
||||
expect(helper.query_path_from_object(array, email2_path)).to eq(email2)
|
||||
expect(helper.query_path_from_object(array, address_path)).to eq(address)
|
||||
end
|
||||
|
||||
it 'returns nil if inputs are not of type Hash and String respectively' do
|
||||
expect(helper.query_path_from_hash({"valid" => true}, ["invalid"])).to eq(nil)
|
||||
expect(helper.query_path_from_hash("invalid", "valid")).to eq(nil)
|
||||
expect(helper.query_path_from_object({"valid" => true}, ["invalid"])).to eq(nil)
|
||||
expect(helper.query_path_from_object("invalid", "valid")).to eq(nil)
|
||||
end
|
||||
|
||||
it 'returns nil if path not found' do
|
||||
@@ -44,10 +70,10 @@ RSpec.describe OAuthsHelper, type: :helper do
|
||||
}
|
||||
|
||||
name_path = "name"
|
||||
expect(helper.query_path_from_hash(hash, name_path)).to eq(nil)
|
||||
expect(helper.query_path_from_object(hash, name_path)).to eq(nil)
|
||||
|
||||
name_path = "info.names[0]"
|
||||
expect(helper.query_path_from_hash(hash, name_path)).to eq(nil)
|
||||
expect(helper.query_path_from_object(hash, name_path)).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user