/** @test */ public function it_returns_created_response_when_talk_is_submitted() { $request = $this->getValidRequest(); // Making these more or less to have speakers return something // sane to test output of 201 Created response. Should be the talk // we submitted! $submission = TalkSubmission::fromNative($request->request->all()); $talk = $submission->toTalk(); $this->speakers->shouldReceive('submitTalk')->once()->with(m::type(\OpenCFP\Domain\Talk\TalkSubmission::class))->andReturn($talk); $response = $this->sut->handleSubmitTalk($request); $this->assertEquals(201, $response->getStatusCode()); $this->assertContains('Happy Path Submission', $response->getContent()); }
/** * Orchestrates the use-case of a speaker submitting a talk. * * @param TalkSubmission $submission * * @return Talk * @throws \Exception */ public function submitTalk(TalkSubmission $submission) { if (!$this->callForProposal->isOpen()) { throw new \Exception('You cannot create talks once the call for papers has ended.'); } $user = $this->identityProvider->getCurrentUser(); // Create talk from submission. $talk = $submission->toTalk(); // Own the talk to the speaker. $talk->user_id = $user->id; $this->talks->persist($talk); $this->dispatcher->dispatch('opencfp.talk.submit', new TalkWasSubmitted($talk)); return $talk; }
/** * @param Request $request * * @return JsonResponse * @throws Exception */ public function handleSubmitTalk(Request $request) { try { $submission = TalkSubmission::fromNative($request->request->all()); $talk = $this->speakers->submitTalk($submission); return $this->setStatusCode(Response::HTTP_CREATED)->respond($talk->toArrayForApi()); } catch (InvalidTalkSubmissionException $e) { return $this->setStatusCode(Response::HTTP_BAD_REQUEST)->respondWithError($e->getMessage()); } catch (NotAuthenticatedException $e) { return $this->respondUnauthorized(); } catch (Exception $e) { return $this->respondInternalError($e->getMessage()); } }
/** @test */ public function it_guards_that_invalid_categories_cannot_be_assigned() { $this->setExpectedException(\OpenCFP\Domain\Talk\InvalidTalkSubmissionException::class, 'category'); TalkSubmission::fromNative(['title' => 'Invalid Categorized Talk', 'description' => 'I do not play by the rules.', 'type' => 'regular', 'level' => 'entry', 'category' => 'skylanders']); }
/** @test */ public function it_doesnt_allow_talk_submissions_after_cfp_has_ended() { $this->callForProposal->shouldReceive('isOpen')->once()->andReturn(false); $this->setExpectedException('Exception', 'has ended'); $submission = TalkSubmission::fromNative(['title' => 'Sample Talk', 'description' => 'Some example talk for our submission', 'type' => 'regular', 'category' => 'api', 'level' => 'mid']); $this->sut->submitTalk($submission); }