Skip to content

Commit bbebaa7

Browse files
authored
Remove hardcoded user_ids and org_ids from users.json (#353)
Now that we're using stubbing in the tests instead of this `users.json` fixture file, the only remaining uses of it were for the "bypass OAuth" mode. Also, since we're now managing user roles within editor-api (instead of in the user info API), it's a lot less obvious the users in the fixture file are actually useful even for the "bypass OAuth" mode. I think it makes the code clearer to remove the fixture file and hard-code some user data for the "bypass OAuth" mode. Closes #308
2 parents 611e7de + 194fb6a commit bbebaa7

File tree

3 files changed

+42
-113
lines changed

3 files changed

+42
-113
lines changed

lib/hydra_public_api_client.rb

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ def fetch_oauth_user(...)
1212
end
1313

1414
def fetch_oauth_user(token:)
15-
if bypass_oauth?
16-
users = stubbed_data['users']
17-
user = users.detect { |attr| attr['id'] == '00000000-0000-0000-0000-000000000000' }
18-
return user
19-
end
15+
return stubbed_user if bypass_oauth?
2016

2117
response = get('userinfo', {}, { Authorization: "Bearer #{token}" })
2218
response.body.to_h
@@ -31,11 +27,25 @@ def bypass_oauth?
3127
ENV.fetch('BYPASS_OAUTH', nil) == 'true'
3228
end
3329

34-
def stubbed_data
35-
path = Rails.root.join('spec/fixtures/users.json')
36-
json = File.read(path)
37-
38-
JSON.parse(json)
30+
def stubbed_user
31+
{
32+
id: '00000000-0000-0000-0000-000000000000',
33+
34+
username: nil,
35+
parentalEmail: nil,
36+
name: 'School Owner',
37+
nickname: 'Owner',
38+
country: 'United Kingdom',
39+
country_code: 'GB',
40+
postcode: nil,
41+
dateOfBirth: nil,
42+
verifiedAt: '2024-01-01T12:00:00.000Z',
43+
createdAt: '2024-01-01T12:00:00.000Z',
44+
updatedAt: '2024-01-01T12:00:00.000Z',
45+
discardedAt: nil,
46+
lastLoggedInAt: '2024-01-01T12:00:00.000Z',
47+
roles: ''
48+
}
3949
end
4050

4151
def conn

lib/user_info_api_client.rb

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,9 @@ class UserInfoApiClient
55
API_KEY = ENV.fetch('USERINFO_API_KEY', '1234')
66

77
class << self
8-
def fetch_by_email(user_email)
9-
return if user_email.blank?
10-
11-
return stubbed_by_email(user_email) if bypass_oauth?
12-
13-
response = conn.get { |r| r.url "/users/#{user_email}" }
14-
return if response.body.blank?
15-
16-
transform_result(response.body.fetch('user', []))
17-
end
18-
198
def fetch_by_ids(user_ids)
209
return [] if user_ids.blank?
21-
return stubbed_by_ids(user_ids) if bypass_oauth?
10+
return stubbed_users(user_ids) if bypass_oauth?
2211

2312
response = conn.get do |r|
2413
r.url '/users'
@@ -51,21 +40,27 @@ def conn
5140
end
5241
end
5342

54-
def stubbed_data
55-
path = Rails.root.join('spec/fixtures/users.json')
56-
json = File.read(path)
57-
58-
JSON.parse(json)
59-
end
60-
61-
def stubbed_by_email(user_email)
62-
data = stubbed_data.fetch('users', nil).find { |d| d['email'] == user_email }
63-
transform_result(data)
64-
end
65-
66-
def stubbed_by_ids(user_ids)
67-
data = stubbed_data.fetch('users', nil).find_all { |d| user_ids.include?(d['id']) }
68-
transform_result(data)
43+
def stubbed_users(user_ids)
44+
user_ids.map do |user_id|
45+
{
46+
id: user_id,
47+
email: "user-#{user_id}@example.com",
48+
username: nil,
49+
parentalEmail: nil,
50+
name: 'School Owner',
51+
nickname: 'Owner',
52+
country: 'United Kingdom',
53+
country_code: 'GB',
54+
postcode: nil,
55+
dateOfBirth: nil,
56+
verifiedAt: '2024-01-01T12:00:00.000Z',
57+
createdAt: '2024-01-01T12:00:00.000Z',
58+
updatedAt: '2024-01-01T12:00:00.000Z',
59+
discardedAt: nil,
60+
lastLoggedInAt: '2024-01-01T12:00:00.000Z',
61+
roles: ''
62+
}
63+
end
6964
end
7065
end
7166
end

spec/fixtures/users.json

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)