From b385df906487cd0a4a30ab7faf56d49b8fbae583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Thu, 14 Nov 2024 17:35:26 +0100 Subject: [PATCH] Update unit tests --- service/test/agama/dbus/users_test.rb | 9 ++++++--- service/test/agama/users_test.rb | 20 +++++++++---------- .../users/RootPasswordPopup.test.jsx | 5 ++++- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/service/test/agama/dbus/users_test.rb b/service/test/agama/dbus/users_test.rb index 744d6cb7db..7dc02cf856 100644 --- a/service/test/agama/dbus/users_test.rb +++ b/service/test/agama/dbus/users_test.rb @@ -24,6 +24,7 @@ require "agama/dbus/interfaces/service_status" require "agama/dbus/users" require "agama/users" +require "y2users" describe Agama::DBus::Users do subject { described_class.new(backend, logger) } @@ -69,16 +70,18 @@ let(:user) { nil } it "returns default data" do - expect(subject.first_user).to eq(["", "", "", false, {}]) + expect(subject.first_user).to eq(["", "", "", false, false, {}]) end end context "if there is an user" do + let(:password) { Y2Users::Password.create_encrypted("12345") } let(:user) do instance_double(Y2Users::User, full_name: "Test user", name: "test", - password_content: "12345") + password: password, + password_content: password.value.to_s) end before do @@ -86,7 +89,7 @@ end it "returns the first user data" do - expect(subject.first_user).to eq(["Test user", "test", "12345", true, {}]) + expect(subject.first_user).to eq(["Test user", "test", password.value.to_s, true, true, {}]) end end end diff --git a/service/test/agama/users_test.rb b/service/test/agama/users_test.rb index 28808cefa4..4314ec25eb 100644 --- a/service/test/agama/users_test.rb +++ b/service/test/agama/users_test.rb @@ -81,7 +81,7 @@ describe "#assign_first_user" do context "when the options given do not present any issue" do it "adds the user to the user's configuration" do - subject.assign_first_user("Jane Doe", "jane", "12345", false, {}) + subject.assign_first_user("Jane Doe", "jane", "12345", false, false, {}) user = users_config.users.by_name("jane") expect(user.full_name).to eq("Jane Doe") expect(user.password).to eq(Y2Users::Password.create_plain("12345")) @@ -89,11 +89,11 @@ context "when a first user exists" do before do - subject.assign_first_user("Jane Doe", "jane", "12345", false, {}) + subject.assign_first_user("Jane Doe", "jane", "12345", false, false, {}) end it "replaces the user with the new one" do - subject.assign_first_user("John Doe", "john", "12345", false, {}) + subject.assign_first_user("John Doe", "john", "12345", false, false, {}) user = users_config.users.by_name("jane") expect(user).to be_nil @@ -104,23 +104,23 @@ end it "returns an empty array of issues" do - issues = subject.assign_first_user("Jane Doe", "jane", "12345", false, {}) + issues = subject.assign_first_user("Jane Doe", "jane", "12345", false, false, {}) expect(issues).to be_empty end end context "when the given arguments presents some critical error" do it "does not add the user to the config" do - subject.assign_first_user("Jonh Doe", "john", "", false, {}) + subject.assign_first_user("Jonh Doe", "john", "", false, false, {}) user = users_config.users.by_name("john") expect(user).to be_nil - subject.assign_first_user("Ldap user", "ldap", "12345", false, {}) + subject.assign_first_user("Ldap user", "ldap", "12345", false, false, {}) user = users_config.users.by_name("ldap") expect(user).to be_nil end it "returns an array with all the issues" do - issues = subject.assign_first_user("Root user", "root", "12345", false, {}) + issues = subject.assign_first_user("Root user", "root", "12345", false, false, {}) expect(issues.size).to eql(1) end end @@ -128,7 +128,7 @@ describe "#remove_first_user" do before do - subject.assign_first_user("Jane Doe", "jane", "12345", false, {}) + subject.assign_first_user("Jane Doe", "jane", "12345", false, false, {}) end it "removes the already defined first user" do @@ -156,7 +156,7 @@ end it "writes system and installer defined users" do - subject.assign_first_user("Jane Doe", "jane", "12345", false, {}) + subject.assign_first_user("Jane Doe", "jane", "12345", false, false, {}) expect(Y2Users::Linux::Writer).to receive(:new) do |target_config, _old_config| user_names = target_config.users.map(&:name) @@ -196,7 +196,7 @@ context "when a first user is defined" do before do - subject.assign_first_user("Jane Doe", "jdoe", "123456", false, {}) + subject.assign_first_user("Jane Doe", "jdoe", "123456", false, false, {}) end it "returns an empty list" do diff --git a/web/src/components/users/RootPasswordPopup.test.jsx b/web/src/components/users/RootPasswordPopup.test.jsx index f6ddd724dc..0624a56161 100644 --- a/web/src/components/users/RootPasswordPopup.test.jsx +++ b/web/src/components/users/RootPasswordPopup.test.jsx @@ -75,7 +75,10 @@ describe("when it is open", () => { expect(confirmButton).toBeEnabled(); await user.click(confirmButton); - expect(mockRootUserMutation.mutateAsync).toHaveBeenCalledWith({ password }); + expect(mockRootUserMutation.mutateAsync).toHaveBeenCalledWith({ + password, + passwordEncrypted: false, + }); expect(onCloseCallback).toHaveBeenCalled(); });