Fakultas Ilmu Komputer UI

Commit 831c6671 authored by Kemas Khaidar Ali Indrakusuma's avatar Kemas Khaidar Ali Indrakusuma
Browse files

Merge branch '1606831035-93' into 'master'

(SPRINT 2) 1606831035 93 - Fitur menampilkan pesan error saat validasi waktu create dan update vacancy agar close time selalu lebih besar dari open time

See merge request !112
parents 159b1da1 0796d4bc
Pipeline #24341 passed with stages
in 13 minutes and 20 seconds
......@@ -114,7 +114,7 @@ export default class CreateVacancy extends React.Component {
Server.sendRequest(url, method, data).then(() => {
browserHistory.push('/lowongan');
}, error => error.then((r) => {
this.modalAlert.open('Gagal Membuat Lowongan', r.detail);
this.modalAlert.open('Gagal Membuat Lowongan', r.error);
this.setState({ formLoading: false });
}));
};
......
from datetime import datetime, timedelta
import requests_mock
from django.contrib.auth.models import User
from rest_framework import status
from rest_framework.test import APITestCase
......@@ -8,6 +7,9 @@ from rest_framework.test import APITestCase
from core.models.accounts import Company, Student, Supervisor
from core.models.vacancies import Vacancy, Application
import json
import requests_mock
class CreateAndUpdateVacancyTest(APITestCase):
today = datetime.today()
......@@ -74,13 +76,12 @@ class CreateAndUpdateVacancyTest(APITestCase):
'close_time': self.tomorrow, 'name': 'new vacancy',
'description': 'new_vacancy ', 'amount': 10, 'benefits':'new_vacancy', 'requirements': 'new_vacancy',
'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
print(response)
self.assertEqual(response.status_code, status.HTTP_200_OK)
vacancy = Vacancy.objects.first()
self.assertEqual(vacancy.benefits, 'new_vacancy')
def test_new_vacancy_failed(self):
def test_new_vacancy_open_time_more_than_close_time_failed(self):
superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
new_company = Company.objects.create(user=superuser, description="lalalaz", status=Company.VERIFIED, logo=None,
address=None)
......@@ -88,9 +89,11 @@ class CreateAndUpdateVacancyTest(APITestCase):
url = '/api/vacancies/'
response = self.client.post(url, {'company': new_company.pk, 'open_time': self.today,
'close_time': self.yesterday, 'name': 'new_vacancy', 'description': 'new_vacancy', 'responsibilities': 'new_vacancy', 'requirements': 'new_vacancy',
'close_time': self.yesterday, 'name': 'newVacancy', 'description': 'newVacancy', 'responsibilities': 'newVacancy', 'requirements': 'newVacancy',
'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.json()['error'], 'Waktu tutup lowongan harus lebih dari waktu buka lowongan!')
vacancies = Vacancy.objects.count()
self.assertEqual(vacancies,0)
......@@ -195,7 +198,7 @@ class CreateAndUpdateVacancyTest(APITestCase):
vacancy = Vacancy.objects.first()
self.assertEqual(vacancy.responsibilities, 'new_vacancy2')
def test_update_vacancy_failed(self):
def test_update_vacancy_open_time_more_than_close_time_failed(self):
superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
new_company = Company.objects.create(user=superuser, description="lalalaz", status=Company.VERIFIED, logo=None,
address=None)
......@@ -206,9 +209,11 @@ class CreateAndUpdateVacancyTest(APITestCase):
url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
response = self.client.patch(url, {'open_time': self.today, 'close_time': self.yesterday,
'name': 'new_vacancy2', 'description': 'new_vacancy2', 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy2',
'name': 'newVacancy2', 'description': 'newVacancy2', 'responsibilities': 'newVacancy2', 'requirements': 'newVacancy2',
'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.json()['error'], 'Waktu tutup lowongan harus lebih dari waktu buka lowongan!')
def test_update_vacancy_with_amount_salary_string_failed(self):
superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
......
......@@ -101,8 +101,8 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
max_accepted_applicants = data['max_accepted_applicants']
if open_time < str(datetime.today()):
raise ValidationError('Waktu buka lowongan harus lebih dari hari ini!')
elif close_time <= open_time:
raise ValidationError('Waktu tutup lowongan harus lebih dari waktu buka lowongan dan tidak sama dengan waktu pembukaan lowongan!')
elif close_time < open_time:
return Response({'error': 'Waktu tutup lowongan harus lebih dari waktu buka lowongan!'}, status=status.HTTP_400_BAD_REQUEST)
elif close_time == open_time:
raise ValidationError('Waktu tutup dan buka lowongan tidak boleh sama!')
vacancy = Vacancy(company=company, open_time=open_time, close_time=close_time, name=name, description=description, salary=salary, working_period=working_period, tag=tag, max_accepted_applicants=max_accepted_applicants)
......@@ -134,8 +134,8 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
max_accepted_applicants = data['max_accepted_applicants']
if open_time < str(datetime.today()):
raise ValidationError('Waktu buka lowongan harus lebih dari hari ini!')
elif close_time <= open_time:
raise ValidationError('Waktu tutup lowongan harus lebih dari waktu buka lowongan dan tidak sama dengan waktu pembukaan lowongan!')
elif close_time < open_time:
return Response({'error': 'Waktu tutup lowongan harus lebih dari waktu buka lowongan!'}, status=status.HTTP_400_BAD_REQUEST)
elif close_time == open_time:
raise ValidationError('Waktu tutup dan buka lowongan tidak boleh sama!')
vacancy.open_time = open_time
......
Supports Markdown
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