/** @test */
 public function update_repair()
 {
     $property = Property::find($this->getTestPropertyId(true));
     factory(Repair::class, 5)->make(['status' => Category::getCategories('repair.status', 'processing', true)])->each(function (Repair $repair) use($property) {
         $property->repairs()->save($repair);
     });
     $property->load(['repairs']);
     $this->call('PUT', '/', ['repair_list' => $property->getRelation('repairs')->pluck('id')]);
     $this->assertResponseOk();
     $this->seeJson();
     $this->assertSame(Category::getCategories('property.status', 'normal', true), Property::find($this->getTestPropertyId(true))->getAttribute('status'));
     foreach (Property::with(['repairs'])->find($this->getTestPropertyId(true))->getRelation('repairs') as $repair) {
         $this->assertSame(Category::getCategories('repair.status', 'finished', true), $repair->getAttribute('status'));
     }
 }
 /**
  * Get random category name.
  *
  * @param string $category
  * @return string
  */
 protected function randomCategoryName($category)
 {
     return Category::getCategories($category)->random()->getAttribute('name');
 }
    $faker = Faker\Factory::create('zh_TW');
    return ['name' => $faker->name, 'describe' => $faker->realText(16), 'category' => Category::getCategories('property')->random()->getAttribute('id'), 'status' => Category::getCategories('property.status')->random()->getAttribute('id'), 'code' => mt_rand(10000000, 99999999)];
});
$factory->define(\App\Affair\Repair::class, function () {
    $faker = Faker\Factory::create('zh_TW');
    return ['user_id' => User::all()->random()->getAttribute('id'), 'title' => mt_rand(0, 1) ? $faker->realText(mt_rand(10, 15)) : '', 'type' => Category::getCategories('repair.type')->random()->getAttribute('id'), 'remark' => $faker->realText(32), 'status' => Category::getCategories('repair.status')->random()->getAttribute('id')];
});
$factory->define(\App\Affair\Loan::class, function () {
    $faker = Faker\Factory::create('zh_TW');
    $time = mt_rand(0, 1);
    // get randomal Timezone
    $began_date = Timezone::all()->random()->getAttribute('date_began_at');
    $day = (new Carbon($began_date))->addDays(rand(1, 10));
    // get date begin/end
    $begin = $day->toDateString();
    $end = $day->addDays(mt_rand(0, 10))->toDateString();
    return ['user_id' => User::all()->random()->getAttribute('id'), 'type' => Category::getCategories('loan.type')->random()->getAttribute('id'), 'date_began_at' => $begin, 'date_ended_at' => $end, 'time_began_at' => $time ? $day->addHours(mt_rand(0, 7))->toTimeString() : null, 'time_ended_at' => $time ? $day->addHours(mt_rand(7, 15))->toTimeString() : null, 'remark' => $faker->realText(32), 'status' => Category::getCategories('loan.status')->random()->getAttribute('id'), 'long_term_token' => $begin != $end ? mt_rand(0, 127) : 1 << date('w', strtotime($begin))];
});
$factory->define(\App\Affair\Timezone::class, function () {
    $faker = Faker\Factory::create('zh_TW');
    $day = Carbon::now()->startOfDay()->addDays(mt_rand(1, 365));
    $stu_start = clone $day;
    $lab_start = clone $day;
    if (mt_rand(0, 1) === 1) {
        $type = Category::getCategoryId('time.type', 'semester');
    } else {
        $type = Category::getCategoryId('time.type', 'vacation');
        $stu_start->subDays(7);
    }
    return ['zone_name' => $faker->realText(mt_rand(10, 15)), 'type' => $type, 'date_began_at' => $day->toDateString(), 'date_ended_at' => $day->addDays(mt_rand(30, 150))->toDateString(), 'stu_date_began_at' => $stu_start->toDateString(), 'lab_date_began_at' => $lab_start->toDateString()];
});
 /** @test */
 public function it_should_get_specific_category_id_if_all_parameters_are_present()
 {
     $this->assertSame(Category::where('category', 'loan.status')->where('name', 'canceled')->first()->getAttribute('id'), Category::getCategories('loan.status', 'canceled', true));
     $this->assertSame(Category::where('category', 'loan.type')->where('name', 'interview')->first()->getAttribute('id'), Category::getCategories('loan.type', 'interview', true));
     $this->assertSame(Category::where('category', 'property')->where('name', 'classroom')->first()->getAttribute('id'), Category::getCategories('property', 'classroom', true));
 }