Commit 1d2b88ef authored by Korko's avatar Korko
Browse files

Change dearsanta-limit to dearsanta-expiration, fix some little issues

parent 8bbc45d6
......@@ -19,16 +19,25 @@ class RandomFormController extends Controller
}
public function handle(RandomFormRequest $request)
{
try {
$this->draw($request);
$message = trans('message.sent');
return $request->ajax() ? response()->json(['message' => $message]) : redirect('/')->with('message', $message);
} catch(SolverException $e) {
$error = trans('error.solution');
return $request->ajax() ? response()->json(['error' => $error], 500) : redirect('/')->with('error', $error);
}
}
protected function draw(Request $request)
{
$participants = $this->getParticipants($request);
$hat = Solver::one($participants, array_column($participants, 'exclusions'));
$this->sendMessages($request, $participants, $hat);
$message = trans('message.sent');
return $request->ajax() ? [$message] : redirect('/')->with('message', $message);
}
protected function getParticipants(Request $request)
......@@ -68,7 +77,7 @@ class RandomFormController extends Controller
{
$dearSantaLink = null;
if ($request->input('dearsanta')) {
$dearSantaLink = $this->getDearSantaLink($santa, $request->input('dearsanta-limit'));
$dearSantaLink = $this->getDearSantaLink($santa, $request->input('dearsanta-expiration'));
}
if (!empty($santa['email'])) {
......
......@@ -28,7 +28,7 @@ class RandomFormRequest extends Request
'phone' => 'array',
'exclusions' => 'array',
'dearsanta' => 'boolean|in:"0","1"',
'dearsanta-limit' => 'required_if:dearsanta,"1"|date|after:tomorrow|before:+1year',
'dearsanta-expiration' => 'required_if:dearsanta,"1"|date|after:tomorrow|before:+1year',
];
if (!empty($this->request->get('name'))) {
......@@ -52,7 +52,7 @@ class RandomFormRequest extends Request
];
$exclusions = $this->request->get('exclusions') ?: [];
$exclusions = isset($exclusions[$key]) ? $exclusions[$key] : [];
$exclusions = isset($exclusions[$key]) ? (array) $exclusions[$key] : [];
foreach ($exclusions as $key2 => $name2) {
$rules += [
'exclusions.'.$key.'.'.$key2 => 'integer|fieldinkeys:name,'.$key,
......
......@@ -24,6 +24,8 @@
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_PATH" value=":memory:"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
......
This diff is collapsed.
This diff is collapsed.
......@@ -33,7 +33,7 @@ module.exports = Vue.extend({
type: "POST",
data : postData,
success: function(data, textStatus, jqXHR) {
alertify.alert(jqXHR.responseJSON[0]);
alertify.alert(jqXHR.responseJSON.message);
app.sent = true;
},
error: function(jqXHR, textStatus, errorThrown) {
......
<template>
<select multiple="multiple">
<select multiple="multiple" :name="name">
<option v-for="option in options" :value="option.value" :key="option.id || option.value">{{ option.text }}</option>
</select>
</template>
......@@ -9,7 +9,7 @@
require('multiple-select');
export default {
props: ['options', 'value', 'placeholder'],
props: ['name', 'options', 'value', 'placeholder'],
mounted: function() {
jQuery(this.$el).multipleSelect({selectAll: false, filter: true, placeholder: this.placeholder, ellipsis: true});
},
......
<?php
return [
'solution' => 'Aucune solution possible',
];
<script type="text/x-template" id="participant-template">
<tr class="participant" :id="'participant_'+idx">
<td class="row">
<label>
<div class="input-group">
<span class="input-group-addon counter">@{{ idx+1 }}</span>
<input type="text" name="name[]" required="required" placeholder="@lang('form.name.placeholder')" v-model="name" class="form-control participant-name" />
</div>
</label>
<div class="input-group">
<span class="input-group-addon counter">@{{ idx+1 }}</span>
<input type="text" :name="'name['+idx+']'" required="required" placeholder="@lang('form.name.placeholder')" v-model="name" class="form-control participant-name" />
</div>
</td>
<td class="row border-left">
<input type="email" name="email[]" placeholder="@lang('form.email.placeholder')" v-model="email" class="form-control participant-email" :required="!phone || dearsanta" />
<input type="email" :name="'email['+idx+']'" placeholder="@lang('form.email.placeholder')" v-model="email" class="form-control participant-email" :required="!phone || dearsanta" />
</td>
<td>
@lang('form.mail-sms')
......@@ -17,11 +15,11 @@
<td class="row border-right">
<div class="input-group">
<span class="input-group-addon lang" lang="fr">(+33)</span>
<input type='tel' pattern='0?[67]\d{8}' :maxlength="(phone[0] === undefined || phone[0] === '0') ? 10 : 9" name="phone[]" placeholder="@lang('form.phone.placeholder')" v-model="phone" @focus="$event.target.value = phone" @blur="$event.target.value = phoneNumber" class="form-control participant-phone" :required="!email" />
<input type='tel' pattern='0?[67]\d{8}' :maxlength="(phone[0] === undefined || phone[0] === '0') ? 10 : 9" :name="'phone['+idx+']'" placeholder="@lang('form.phone.placeholder')" v-model="phone" @focus="$event.target.value = phone" @blur="$event.target.value = phoneNumber" class="form-control participant-phone" :required="!email" />
</div>
</td>
<td class="row border-right text-left participant-exclusions-wrapper">
<select2 :options="participantNames" v-model="exclusions" placeholder="@lang('form.exclusions.placeholder')"></select2>
<select2 :name="'exclusions['+idx+'][]'" :options="participantNames" v-model="exclusions" placeholder="@lang('form.exclusions.placeholder')"></select2>
</td>
<td class="row participant-remove-wrapper">
<button type="button" class="btn btn-danger participant-remove" :disabled="participants.length <= 2" @click="$emit('delete')">
......
......@@ -14,7 +14,7 @@ class RequestCase extends TestCase
{
$server = ['HTTP_X-Requested-With' => 'XMLHttpRequest'];
$response = $this->call('POST', $url, $postArgs, [], [], $server);
$this->assertEquals($code, $response->status());
$this->assertEquals($code, $response->status(), $response);
return json_decode($response->content(), true);
}
......
......@@ -84,8 +84,9 @@ class RequestTest extends RequestCase
'contentSMS' => 'test sms "{SANTA}\' => &{TARGET}',
'dearsanta' => '0',
], 200);
$this->assertEquals(['Envoyé avec succès !'], $content);
$this->assertEquals(['message' => 'Envoyé avec succès !'], $content);
// Nothing, no record, no dearsanta
$this->assertEquals(0, Draw::count());
$this->assertEquals(0, Participant::count());
}
......@@ -158,9 +159,9 @@ class RequestTest extends RequestCase
'contentMail' => 'test mail {SANTA} => {TARGET}',
'contentSMS' => 'test sms "{SANTA}\' => &{TARGET}',
'dearsanta' => '1',
'dearsanta-limit' => date('Y-m-d', strtotime('+2 days')),
'dearsanta-expiration' => date('Y-m-d', strtotime('+2 days')),
], 200);
$this->assertEquals(['Envoyé avec succès !'], $content);
$this->assertEquals(['message' => 'Envoyé avec succès !'], $content);
$this->assertEquals(1, Draw::count());
$this->assertEquals(3, Participant::count());
......
......@@ -110,14 +110,14 @@ class ValidationTest extends RequestCase
// dearsanta enabled, need emails and limit
$content = $this->ajaxPost('/', ['name' => ['toto', 'tata', 'tutu'], 'phone' => ['0612345678', '0612345678', '0612345678'], 'dearsanta' => '1'], 422);
$this->assertArrayKeysEquals(['g-recaptcha-response', 'contentSMS', 'email.0', 'email.1', 'email.2', 'dearsanta-limit'], $content);
$this->assertArrayKeysEquals(['g-recaptcha-response', 'contentSMS', 'email.0', 'email.1', 'email.2', 'dearsanta-expiration'], $content);
// dearsanta enabled, invalid limit (too soon)
$content = $this->ajaxPost('/', ['name' => ['toto', 'tata', 'tutu'], 'phone' => ['0612345678', '0612345678', '0612345678'], 'dearsanta' => '1', 'dearsanta-limit' => date('Y-m-d')], 422);
$this->assertArrayKeysEquals(['g-recaptcha-response', 'contentSMS', 'email.0', 'email.1', 'email.2', 'dearsanta-limit'], $content);
$content = $this->ajaxPost('/', ['name' => ['toto', 'tata', 'tutu'], 'phone' => ['0612345678', '0612345678', '0612345678'], 'dearsanta' => '1', 'dearsanta-expiration' => date('Y-m-d')], 422);
$this->assertArrayKeysEquals(['g-recaptcha-response', 'contentSMS', 'email.0', 'email.1', 'email.2', 'dearsanta-expiration'], $content);
// dearsanta enabled, limit valid
$content = $this->ajaxPost('/', ['name' => ['toto', 'tata', 'tutu'], 'phone' => ['0612345678', '0612345678', '0612345678'], 'dearsanta' => '1', 'dearsanta-limit' => date('Y-m-d', strtotime('+3 day'))], 422);
$content = $this->ajaxPost('/', ['name' => ['toto', 'tata', 'tutu'], 'phone' => ['0612345678', '0612345678', '0612345678'], 'dearsanta' => '1', 'dearsanta-expiration' => date('Y-m-d', strtotime('+3 day'))], 422);
$this->assertArrayKeysEquals(['g-recaptcha-response', 'contentSMS', 'email.0', 'email.1', 'email.2'], $content);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment