Skip to content

Commit 3220e88

Browse files
authored
Unskip g_suite_account_service/create_spec.rb and replace fixtures with factories (#3046)
#3008 Similar to #3043, move the production specific skip lower in the stack so that the rest of the service's API is upheld. * Unskip test Move environment check into specific client wrappers Because email has text and html, must use body.encoded https://stackoverflow.com/questions/29454102/in-rails-why-is-my-mail-body-empty-only-in-my-test Fix variables (event was missing, @g_suite is actually g_suite) * Replace fixtures with factories
1 parent 59e677d commit 3220e88

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

app/services/g_suite_account_service/create.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ def initialize(g_suite:, current_user:,
1414
end
1515

1616
def run
17-
unless Rails.env.production?
18-
puts "☣️ In production, we would currently be creating the GSuite on Google Admin ☣️"
19-
return
20-
end
21-
2217
ActiveRecord::Base.transaction do
2318
# 1. Create local account
2419
g_suite_account.save!

app/services/partners/google/g_suite/create_user.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ def initialize(given_name:, family_name:, password:, primary_email:, recovery_em
1818
end
1919

2020
def run
21+
unless Rails.env.production?
22+
puts "☣️ In production, we would currently be creating the GSuite on Google Admin ☣️"
23+
return
24+
end
25+
2126
directory_client.insert_user(user_object)
2227
end
2328

app/services/partners/google/g_suite/org_unit.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ def initialize(org_unit_path:)
1111
end
1212

1313
def run
14+
unless Rails.env.production?
15+
puts "☣️ In production, we would currently be creating the GSuite on Google Admin ☣️"
16+
return
17+
end
18+
1419
directory_client.get_org_unit(gsuite_customer_id, org_unit_path_without_leading_slash)
1520
rescue ::Google::Apis::ClientError => e
1621
# re-raise unless 404

spec/services/g_suite_account_service/create_spec.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22

33
require "rails_helper"
44

5-
RSpec.describe GSuiteAccountService::Create, type: :model, skip: true do
6-
fixtures "users", "events", "g_suites"
7-
8-
let(:g_suite) { g_suites(:g_suite1) }
9-
let(:current_user) { users(:user1) }
5+
RSpec.describe GSuiteAccountService::Create, type: :model do
6+
let(:g_suite) { create(:g_suite, domain: "event.example.com") }
7+
let(:current_user) { create(:user) }
8+
let(:event) { create(:event) }
109

1110
let(:backup_email) { "[email protected]" }
1211
let(:address) { "address" }
1312
let(:first_name) { "First" }
1413
let(:last_name) { "Last" }
1514

1615
let(:remote_org_unit) do
17-
ou_name = "##{event.id} G##{@g_suite.id}"
16+
ou_name = "##{event.id} G##{g_suite.id}"
1817
double("remoteOrgUnit", name: ou_name, org_unit_id: "id:1234", org_unit_path: "/Events/#{ou_name}")
1918
end
2019

@@ -54,8 +53,8 @@
5453

5554
expect(mail.to).to eql(["[email protected]"])
5655
expect(mail.subject).to include("Your Google Workspace account via Bank is ready")
57-
expect(mail.body).to include("address@event1.example.com")
58-
expect(mail.body).to include(g_suite_account.initial_password)
56+
expect(mail.body.encoded).to include("address@event.example.com")
57+
expect(mail.body.encoded).to include(g_suite_account.initial_password)
5958
end
6059

6160
context "when remote org unit does not exist" do
@@ -79,7 +78,7 @@
7978
it "assigns remote_org_unit_path" do
8079
expect do
8180
service.run
82-
end.to change(g_suite.reload, :remote_org_unit_path).to("/Events/##{event.id} G##{@g_suite.id}")
81+
end.to change(g_suite.reload, :remote_org_unit_path).to("/Events/##{event.id} G##{g_suite.id}")
8382
end
8483
end
8584

@@ -94,7 +93,7 @@
9493
end.not_to change(GSuiteAccount, :count)
9594
end
9695

97-
it "raises an errro" do
96+
it "raises an error" do
9897
expect do
9998
service.run
10099
end.to raise_error(ArgumentError)
@@ -106,7 +105,7 @@
106105
it "builds" do
107106
result = service.send(:full_email_address)
108107

109-
expect(result).to eql("address@event1.example.com")
108+
expect(result).to eql("address@event.example.com")
110109
end
111110
end
112111
end

0 commit comments

Comments
 (0)