/** * Create a day's sleep */ private function createDaySleep($index, $finishMinutes) { $today = Carbon::today(); $this->date = $today->subDays($index); $entry = new Timer(['start' => $this->date->hour(16)->format('Y-m-d H:i:s'), 'finish' => $this->date->hour(17)->minute($finishMinutes)->format('Y-m-d H:i:s')]); $entry->user()->associate($this->user); $entry->activity()->associate(Activity::where('name', 'sleep')->where('user_id', $this->user->id)->first()); $entry->save(); }
/** * For when the user gives both start and finish times * @test * @return void */ public function it_can_insert_a_manual_timer_entry() { DB::beginTransaction(); $this->logInUser(); $timer = ['start' => '2015-12-01 21:00:00', 'finish' => '2015-12-01 22:10:05', 'activity_id' => Activity::where('name', 'work')->first()->id]; $response = $this->call('POST', '/api/timers', $timer); // dd($response); $content = json_decode($response->getContent(), true); // dd($content); $this->checkTimerKeysExist($content); $this->assertEquals('2015-12-01 21:00:00', $content['start']); $this->assertEquals('2015-12-01 22:10:05', $content['finish']); $this->assertEquals('01/12/15', $content['startDate']); $this->assertEquals(Response::HTTP_CREATED, $response->getStatusCode()); DB::rollBack(); }
/** * Todo: check values are correct? Check it doesn't error if there is no timer in progress? * @test * @return void */ public function it_checks_for_timer_in_progress() { DB::beginTransaction(); $this->logInUser(); $timer = ['start' => '2015-12-01 21:00:00', 'activity_id' => Activity::where('name', 'work')->first()->id]; $response = $this->call('POST', '/api/timers', $timer); $content = json_decode($response->getContent(), true); $this->assertEquals(Response::HTTP_CREATED, $response->getStatusCode()); $response = $this->call('GET', '/api/timers/checkForTimerInProgress'); $content = json_decode($response->getContent(), true); $this->assertArrayHasKey('id', $content); $this->assertArrayHasKey('start', $content); $this->assertArrayHasKey('startDate', $content); $this->assertArrayHasKey('activity', $content); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); DB::rollBack(); }