From 09b2cb70448bf700d73e11587fe76ce5095fe7a8 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Tue, 6 Sep 2022 18:01:02 +0200 Subject: [PATCH] Add InitializeGrupsTest --- .../Initialize/InitializeGroupsTest.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/Feature/Initialize/InitializeGroupsTest.php diff --git a/tests/Feature/Initialize/InitializeGroupsTest.php b/tests/Feature/Initialize/InitializeGroupsTest.php new file mode 100644 index 00000000..ea8c04d9 --- /dev/null +++ b/tests/Feature/Initialize/InitializeGroupsTest.php @@ -0,0 +1,47 @@ +fetches(null, [1000 => ['name' => 'testgroup']]) + ->fetches(1000, []); + + $this->withoutExceptionHandling()->login()->loginNami(); + + (new InitializeGroups(app(NamiSettings::class)->login()))->handle(); + + $this->assertDatabaseHas('groups', ['nami_id' => 1000, 'name' => 'testgroup']); + } + + public function testItInitializesSubgroups(): void + { + app(GroupFake::class) + ->fetches(null, [1000 => ['name' => 'testgroup']]) + ->fetches(1000, [ + 1001 => ['name' => 'subgroup1'], + 1002 => ['name' => 'subgroup2'], + ]) + ->fetches(1001, []) + ->fetches(1002, []); + + $this->withoutExceptionHandling()->login()->loginNami(); + + (new InitializeGroups(app(NamiSettings::class)->login()))->handle(); + + $this->assertDatabaseHas('groups', ['nami_id' => 1000, 'name' => 'testgroup']); + $this->assertDatabaseHas('groups', ['nami_id' => 1001, 'name' => 'subgroup1']); + $this->assertDatabaseHas('groups', ['nami_id' => 1002, 'name' => 'subgroup2']); + } +}