public function testIf_fact_and_question_returned()
 {
     //arrange
     $fact_id = Fact::create(['user_id' => 1, 'fact' => 'I hope you learn to make it on your own'])->id;
     $questions = $this->getSampleQuestions($fact_id);
     Question::insert($questions);
     //act
     $questionRandomizer = new QuestionSelector();
     $fact_with_question = $questionRandomizer->getRandomQuestion($fact_id);
     //assert
     $this->assertArrayHasKeys(['fact_id', 'user_id', 'question_title', 'question_type', 'fact'], $fact_with_question);
 }
Exemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @param  $user_id user URI segment
  * @return Response
  */
 public function store(Request $request, $user_id = null)
 {
     if (!$request->input('newFact')) {
         return $this->respondUnprocessed("Unprocessed: Please check data sent and try again");
     } else {
         $createdFact = Fact::create(['user_id' => $user_id, 'fact' => $request->input('newFact')]);
         $insert_id = $createdFact->id;
         // We need to do some other tasks like get questions for new fact
         $this->dispatch(new FactInserted(Auth::user(), $createdFact));
         $metadata = ['last_inserted_id' => $insert_id];
         return $this->respondCreated("Data successfully created", $metadata);
     }
 }
Exemplo n.º 3
0
 public function testIf_user_edits_unauthorized_resource_throw_error()
 {
     //arrange
     // User is trying to edit a resource he doesn't posses
     $this->authorizeTestUser();
     // user_id = 1
     $fact_id = Fact::create(['user_id' => 10, 'fact' => 'If I give you the funk, you gon take it?'])->id;
     $url = "api/v1/user/1/fact/{$fact_id}/tag";
     $tag = ['tag_name' => "This is a test tag"];
     // act
     $this->getJson($url, "POST", $tag);
     //assert
     $this->assertResponseStatus('403');
 }
 public function insertAnswerAsFactWithDefaultQuestions($answer)
 {
     $fact_id = Fact::create(['user_id' => $this->user_id, 'fact' => $answer])->id;
     $questions = [['fact_id' => $fact_id, 'question_title' => 'Can you create a test question from this fact?', 'question_type' => 1], ['fact_id' => $fact_id, 'question_title' => 'Write this fact in your own words', 'question_type' => 2], ['fact_id' => $fact_id, 'question_title' => 'Write a paragraph about the fact and its related implications', 'question_type' => 3], ['fact_id' => $fact_id, 'question_title' => 'How can you apply this to your day, or life in general?', 'question_type' => 4], ['fact_id' => $fact_id, 'question_title' => 'Can you find a related fact to this fact', 'question_type' => 5]];
     Question::insert($questions);
 }
Exemplo n.º 5
0
 /**
  * @param $user
  * @param $quantity
  */
 protected function mockFacts($user, $quantity)
 {
     while ($quantity--) {
         Fact::create(['user_id' => $user->id, 'fact' => 'I provide that new new']);
     }
 }