callApiWithToken($service, 'get', route('apiV2.stats.brandStats'), [ 'start' => Carbon::now()->subMonths(3)->format('Y-m-d'), 'end' => Carbon::now()->format('Y-m-d') ]); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::OK()); $json->assertStructure([ 'data' => [ 'stats' => [ '*' => [ 'date', 'active', 'inactive', 'old_accounts', 'new_accounts', 'total_accounts', 'total_opt_in' ] ] ] ]); } /** * route: apiV2.stats.brandStats */ public function testStatsByQuestion() { $service = Service::firstOrFail(); $question = Question::whereBrandId($service->brand->id)->firstOrFail(); $answersIds = $question->answers()->pluck('id'); $start = Carbon::now()->subDays(3); $end = Carbon::now(); $response = $this->callApiWithToken($service, 'get', route('apiV2.stats.questionStats'), [ 'question' => $question->id, 'start' => $start->format('Y-m-d'), 'end' => $end->format('Y-m-d') ]); $datesIndexes = []; do { $datesIndexes[$start->format('Y-m-d')] = $answersIds // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed ->keys()->all(); $start = $start->addDay(); } while ($start->lessThanOrEqualTo($end)); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::OK()); $json->assertStructure([ 'data' => [ 'answers' => [ '*' => [ 'id', 'answer' ] ], 'stats' => $datesIndexes ] ]); } }