Updated request variable, updated api test
This commit is contained in:
parent
4bb4e7c56b
commit
07eb2af135
6
resources/js/app.js
vendored
6
resources/js/app.js
vendored
@ -28,7 +28,7 @@ m.mount(document.body.querySelector('.container'), {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
Siswa.cariData({
|
Siswa.cariData({
|
||||||
nisn: e.target.elements.nisn.value,
|
nisn: e.target.elements.nisn.value,
|
||||||
tglLahir: e.target.elements.tglLahir.value,
|
tanggalLahir: e.target.elements.tanggalLahir.value,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -39,8 +39,8 @@ m.mount(document.body.querySelector('.container'), {
|
|||||||
m('p.input-helper', 'Nomor Induk Siswa Nasional.'),
|
m('p.input-helper', 'Nomor Induk Siswa Nasional.'),
|
||||||
]),
|
]),
|
||||||
m('.form-group', [
|
m('.form-group', [
|
||||||
m('label.form-label[for=input-tglLahir]', 'Tanggal Lahir'),
|
m('label.form-label[for=input-tanggalLahir]', 'Tanggal Lahir'),
|
||||||
m('input.form-input.input-text#input-tglLahir[name=tglLahir][type=text][autocomplete=off][required]'),
|
m('input.form-input.input-text#input-tanggalLahir[name=tanggalLahir][type=text][autocomplete=off][required]'),
|
||||||
m('p.input-helper', 'Tanggal lahir dengan format YYYYMMDD. Contoh: untuk tanggal 29 Mei 2000 ditulis 20000529'),
|
m('p.input-helper', 'Tanggal lahir dengan format YYYYMMDD. Contoh: untuk tanggal 29 Mei 2000 ditulis 20000529'),
|
||||||
]),
|
]),
|
||||||
m('button.form-submit[type=submit]', 'Lihat'),
|
m('button.form-submit[type=submit]', 'Lihat'),
|
||||||
|
@ -18,17 +18,16 @@ Route::post('/siswa', function (Request $request) {
|
|||||||
// Auto redirect on fail
|
// Auto redirect on fail
|
||||||
Validator::make($request->all(), [
|
Validator::make($request->all(), [
|
||||||
'nisn' => 'required|regex:/^[0-9]+$/',
|
'nisn' => 'required|regex:/^[0-9]+$/',
|
||||||
'tglLahir' => 'required|regex:/^[0-9]+$/',
|
'tanggalLahir' => 'required|regex:/^[0-9]+$/',
|
||||||
], [
|
], [
|
||||||
'required' => 'Kolom :attribute harus diisi.',
|
'required' => 'Kolom :attribute harus diisi.',
|
||||||
'string' => 'Kolom :attribute tidak sesuai.',
|
|
||||||
'regex' => 'Kolom :attribute tidak sesuai.',
|
'regex' => 'Kolom :attribute tidak sesuai.',
|
||||||
])->validate();
|
])->validate();
|
||||||
|
|
||||||
// Look for the given inputs in the resource
|
// Look for the given inputs in the resource
|
||||||
$tglLahir = Carbon\Carbon::parse($request->tglLahir);
|
$tanggalLahir = Carbon\Carbon::parse($request->tanggalLahir)->format('Y-m-d');
|
||||||
$siswa = App\Siswa::where('nisn', $request->nisn)
|
$siswa = App\Siswa::where('nisn', $request->nisn)
|
||||||
->where('tanggal_lahir', $tglLahir)
|
->where('tanggal_lahir', $tanggalLahir)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
// Redirect with error if not found
|
// Redirect with error if not found
|
||||||
|
@ -12,7 +12,7 @@ class ApplicationTest extends TestCase
|
|||||||
|
|
||||||
public function testCariDataSiswaSalahGagal()
|
public function testCariDataSiswaSalahGagal()
|
||||||
{
|
{
|
||||||
$response = $this->json('POST', '/api/siswa', ['nama' => 'Sally', 'nisn' => '1234567890']);
|
$response = $this->json('POST', '/api/siswa', ['nisn' => '1234567890', 'tanggalLahir' => '20190510']);
|
||||||
|
|
||||||
$response
|
$response
|
||||||
->assertStatus(404)
|
->assertStatus(404)
|
||||||
@ -23,30 +23,30 @@ class ApplicationTest extends TestCase
|
|||||||
|
|
||||||
public function testCariDataSiswaTidakDiisiGagal()
|
public function testCariDataSiswaTidakDiisiGagal()
|
||||||
{
|
{
|
||||||
$response = $this->json('POST', '/api/siswa', ['nama' => '', 'nisn' => '']);
|
$response = $this->json('POST', '/api/siswa', ['nisn' => '', 'tanggalLahir' => '']);
|
||||||
|
|
||||||
$response
|
$response
|
||||||
->assertStatus(422)
|
->assertStatus(422)
|
||||||
->assertJson([
|
->assertJson([
|
||||||
'message' => 'The given data was invalid.',
|
'message' => 'The given data was invalid.',
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'nama' => ['Kolom nama harus diisi.'],
|
|
||||||
'nisn' => ['Kolom nisn harus diisi.'],
|
'nisn' => ['Kolom nisn harus diisi.'],
|
||||||
|
'tanggalLahir' => ['Kolom tanggal lahir harus diisi.'],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCariDataSiswaTidakSesuaiGagal()
|
public function testCariDataSiswaTidakSesuaiGagal()
|
||||||
{
|
{
|
||||||
$response = $this->json('POST', '/api/siswa', ['nama' => ['Sally'], 'nisn' => 'abcdefghij']);
|
$response = $this->json('POST', '/api/siswa', ['nisn' => '1abcdefghij9', 'tanggalLahir' => '2019-05-10']);
|
||||||
|
|
||||||
$response
|
$response
|
||||||
->assertStatus(422)
|
->assertStatus(422)
|
||||||
->assertJson([
|
->assertJson([
|
||||||
'message' => 'The given data was invalid.',
|
'message' => 'The given data was invalid.',
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'nama' => ['Kolom nama tidak sesuai.'],
|
|
||||||
'nisn' => ['Kolom nisn tidak sesuai.'],
|
'nisn' => ['Kolom nisn tidak sesuai.'],
|
||||||
|
'tanggalLahir' => ['Kolom tanggal lahir tidak sesuai.'],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -55,7 +55,8 @@ class ApplicationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$siswa = factory(\App\Siswa::class)->create();
|
$siswa = factory(\App\Siswa::class)->create();
|
||||||
|
|
||||||
$response = $this->json('POST', '/api/siswa', ['nama' => $siswa->nama, 'nisn' => $siswa->nisn]);
|
$response = $this->json('POST', '/api/siswa', ['nisn' => $siswa->nisn, 'tanggalLahir' => $siswa->tanggal_lahir->format('Ymd')]);
|
||||||
|
$this->assertDatabaseHas('siswas', $siswa->toArray());
|
||||||
|
|
||||||
$response
|
$response
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
@ -73,7 +74,7 @@ class ApplicationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$siswa = factory(\App\Siswa::class)->create();
|
$siswa = factory(\App\Siswa::class)->create();
|
||||||
|
|
||||||
$response = $this->json('POST', '/api/siswa', ['nama' => $siswa->nama, 'nisn' => $siswa->nisn]);
|
$response = $this->json('POST', '/api/siswa', ['nisn' => $siswa->nisn, 'tanggalLahir' => $siswa->tanggal_lahir->format('Ymd')]);
|
||||||
|
|
||||||
$this->assertDatabaseHas('access_logs', [
|
$this->assertDatabaseHas('access_logs', [
|
||||||
'siswa_id' => $siswa->id,
|
'siswa_id' => $siswa->id,
|
||||||
@ -84,7 +85,7 @@ class ApplicationTest extends TestCase
|
|||||||
{
|
{
|
||||||
$siswas = factory(\App\Siswa::class, 50)->create();
|
$siswas = factory(\App\Siswa::class, 50)->create();
|
||||||
|
|
||||||
$request = $this->json('POST', '/api/siswa', ['nama' => $siswas[0]->nama, 'nisn' => $siswas[0]->nisn]);
|
$request = $this->json('POST', '/api/siswa', ['nisn' => $siswas[0]->nisn, 'tanggalLahir' => $siswas[0]->tanggal_lahir->format('Ymd')]);
|
||||||
|
|
||||||
$response = $this->json('GET', '/api/access_log');
|
$response = $this->json('GET', '/api/access_log');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user