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']); + } +}