-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testing the progress report generation
- Loading branch information
Showing
3 changed files
with
102 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require "test_helper" | ||
|
||
class ::Projects::SimplecovProgressTest < ActiveSupport::TestCase | ||
def setup | ||
organization = Organization.create!(handle: "test-organization") | ||
@project = Project.create!(handle: "test-project", organization:) | ||
|
||
def create_report(created_at, general_coverage) | ||
Report.create!( | ||
organization: @project.organization, | ||
project: @project, | ||
name: "name", | ||
kind: :simplecov, | ||
created_at:, | ||
results: { general_coverage: } | ||
) | ||
end | ||
|
||
create_report("2024-11-27 01:01:01", 87.7) | ||
|
||
create_report("2024-11-28 01:01:01", nil) | ||
|
||
create_report("2024-11-29 01:01:01", 88.1).update!(results: {}) | ||
|
||
create_report("2024-11-30 01:01:01", 89.1) | ||
create_report("2024-11-30 02:02:02", 89.2) | ||
|
||
create_report("2024-12-01 01:01:01", 90.1) | ||
create_report("2024-12-01 02:02:02", 92) | ||
create_report("2024-12-01 03:03:03", 90.3) | ||
end | ||
|
||
def test_one_datapoint_per_date | ||
results = ::Projects::SimplecovProgress.new(@project).call | ||
|
||
assert_equal(results.map do |created_at, coverage| | ||
[ created_at.to_date.to_s, coverage ] | ||
end, [ | ||
[ "2024-11-27", 87.7 ], | ||
[ "2024-11-30", 89.1 ], | ||
[ "2024-12-01", 90.1 ] | ||
]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,67 @@ | ||
require "test_helper" | ||
|
||
module Users | ||
class OmniauthUpserterTest < ActiveSupport::TestCase | ||
Auth = Struct.new(:provider, :uid, :info) | ||
AuthInfo = Struct.new(:nickname, :email) | ||
class Users::OmniauthUpserterTest < ActiveSupport::TestCase | ||
Auth = Struct.new(:provider, :uid, :info) | ||
AuthInfo = Struct.new(:nickname, :email) | ||
|
||
def setup | ||
@auth = Auth.new( | ||
provider: "github", | ||
uid: "12345", | ||
info: AuthInfo.new( | ||
nickname: "testuser", | ||
email: "[email protected]" | ||
) | ||
def setup | ||
@auth = Auth.new( | ||
provider: "github", | ||
uid: "12345", | ||
info: AuthInfo.new( | ||
nickname: "testuser", | ||
email: "[email protected]" | ||
) | ||
) | ||
|
||
@organization = Organization.create!( | ||
handle: "test-organization", | ||
user_queue: [ "testuser" ] | ||
) | ||
end | ||
|
||
def test_creates_new_user_if_not_existing | ||
assert_difference "User.count", 1 do | ||
OmniauthUpserter.new(@auth).call | ||
end | ||
@organization = Organization.create!( | ||
handle: "test-organization", | ||
user_queue: [ "testuser" ] | ||
) | ||
end | ||
|
||
user = User.find_by(uid: @auth.uid) | ||
assert_equal "github", user.provider | ||
assert_equal "12345", user.uid | ||
assert_equal "testuser", user.handle | ||
assert_equal "[email protected]", user.email | ||
def test_creates_new_user_if_not_existing | ||
assert_difference "User.count", 1 do | ||
::Users::OmniauthUpserter.new(@auth).call | ||
end | ||
|
||
def test_finds_existing_user_if_already_exists | ||
existing_user = User.create!( | ||
provider: "github", | ||
uid: "12345", | ||
handle: "testuser", | ||
email: "[email protected]", | ||
password: "securepassword" | ||
) | ||
user = User.find_by(uid: @auth.uid) | ||
assert_equal "github", user.provider | ||
assert_equal "12345", user.uid | ||
assert_equal "testuser", user.handle | ||
assert_equal "[email protected]", user.email | ||
end | ||
|
||
assert_no_difference "User.count" do | ||
OmniauthUpserter.new(@auth).call | ||
end | ||
def test_finds_existing_user_if_already_exists | ||
existing_user = User.create!( | ||
provider: "github", | ||
uid: "12345", | ||
handle: "testuser", | ||
email: "[email protected]", | ||
password: "securepassword" | ||
) | ||
|
||
user = User.find_by(uid: @auth.uid) | ||
assert_equal existing_user.id, user.id | ||
assert_no_difference "User.count" do | ||
::Users::OmniauthUpserter.new(@auth).call | ||
end | ||
|
||
def test_enrolls_user_from_organization_queues | ||
OmniauthUpserter.new(@auth).call | ||
user = User.find_by(uid: @auth.uid) | ||
user = User.find_by(uid: @auth.uid) | ||
assert_equal existing_user.id, user.id | ||
end | ||
|
||
assert @organization.reload.user_queue.exclude?(user.handle) | ||
assert OrganizationUser.exists?(organization: @organization, user: user) | ||
end | ||
def test_enrolls_user_from_organization_queues | ||
::Users::OmniauthUpserter.new(@auth).call | ||
user = User.find_by(uid: @auth.uid) | ||
|
||
assert @organization.reload.user_queue.exclude?(user.handle) | ||
assert OrganizationUser.exists?(organization: @organization, user: user) | ||
end | ||
|
||
def test_does_not_fail_when_handle_not_in_queue | ||
@organization.update!(user_queue: []) | ||
def test_does_not_fail_when_handle_not_in_queue | ||
@organization.update!(user_queue: []) | ||
|
||
assert_nothing_raised do | ||
OmniauthUpserter.new(@auth).call | ||
end | ||
assert_nothing_raised do | ||
::Users::OmniauthUpserter.new(@auth).call | ||
end | ||
end | ||
end |