prepareDatabase([ 'users' => [ $this->normalUser(), ], ]); } /** * @test */ public function admin_cannot_create_group_without_data() { $response = $this->send( $this->request('POST', '/api/groups', [ 'authenticatedAs' => 1, 'json' => [], ]) ); $this->assertEquals(422, $response->getStatusCode()); } /** * @test */ public function admin_can_create_group() { $response = $this->send( $this->request('POST', '/api/groups', [ 'authenticatedAs' => 1, 'json' => [ 'data' => [ 'attributes' => [ 'nameSingular' => 'flarumite', 'namePlural' => 'flarumites', 'icon' => 'test', 'color' => null, ], ], ], ]) ); $this->assertEquals(201, $response->getStatusCode()); // Verify API response body $data = json_decode($response->getBody()->getContents(), true); $this->assertEquals('flarumite', Arr::get($data, 'data.attributes.nameSingular')); $this->assertEquals('flarumites', Arr::get($data, 'data.attributes.namePlural')); $this->assertEquals('test', Arr::get($data, 'data.attributes.icon')); $this->assertNull(Arr::get($data, 'data.attributes.color')); // Verify database entry $group = Group::where('icon', 'test')->firstOrFail(); $this->assertEquals('flarumite', $group->name_singular); $this->assertEquals('flarumites', $group->name_plural); $this->assertEquals('test', $group->icon); $this->assertNull($group->color); } /** * @test */ public function normal_user_cannot_create_group() { $response = $this->send( $this->request('POST', '/api/groups', [ 'authenticatedAs' => 2, 'json' => [ 'data' => [ 'attributes' => [ 'nameSingular' => 'flarumite', 'namePlural' => 'flarumites', 'icon' => 'test', 'color' => null, ], ], ], ]) ); $this->assertEquals(403, $response->getStatusCode()); } }