Fakultas Ilmu Komputer UI

Commit b2d4288d authored by Glenda Emanuella Sutanto's avatar Glenda Emanuella Sutanto
Browse files

Merge branch 'add-program-end-date-field-in-cart' into 'staging'

Add program end date field in cart

See merge request !75
parents 96412075 efd1063e
Pipeline #80295 passed with stages
in 14 minutes and 34 seconds
PROGRAM_DURATION = {
"BABY_1": 30,
"BABY_3": 90,
"GOALS_1": 30,
"GOALS_3": 90,
"GOALS_6": 180,
"BALANCED_1": 30,
"BALANCED_3": 90,
"BALANCED_6": 180,
"TRIAL": 7
}
# Generated by Django 3.1 on 2021-05-31 04:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('payment', '0005_auto_20210510_2324'),
]
operations = [
migrations.AddField(
model_name='cart',
name='program_end_date',
field=models.DateField(blank=True, null=True),
),
]
...@@ -22,6 +22,7 @@ class Cart(models.Model): ...@@ -22,6 +22,7 @@ class Cart(models.Model):
) )
transaction_status = models.CharField(max_length=128,\ transaction_status = models.CharField(max_length=128,\
choices=TRANSACTION_STATUS.choices, default=TRANSACTION_STATUS.UNPAID) choices=TRANSACTION_STATUS.choices, default=TRANSACTION_STATUS.UNPAID)
program_end_date = models.DateField(null=True,blank=True)
def __str__(self): def __str__(self):
return f"{self.user} - {self.program.unique_code} - {self.nutritionist}" return f"{self.user} - {self.program.unique_code} - {self.nutritionist}"
import json import json
from unittest.mock import patch from unittest.mock import patch
from datetime import date, timedelta
from rest_framework.test import APITestCase from rest_framework.test import APITestCase
from django.test import TestCase from django.test import TestCase
from rest_framework import status from rest_framework import status
from rest_framework.response import Response from constants.program_duration import PROGRAM_DURATION
from constants.transaction_status import TransactionStatus as TRANSACTION_STATUS
from .models import Cart from .models import Cart
from .serializers import CartSerializer from .serializers import CartSerializer
from .views import PaymentViewSet
from authentication.models import CustomUser from authentication.models import CustomUser
from dietela_quiz.models import * from dietela_quiz.models import *
from dietela_program.models import DietelaProgram from dietela_program.models import DietelaProgram
...@@ -38,8 +37,8 @@ class CartTests(APITestCase): ...@@ -38,8 +37,8 @@ class CartTests(APITestCase):
) )
cls.dietela_program_3 = DietelaProgram.objects.create( cls.dietela_program_3 = DietelaProgram.objects.create(
unique_code="PRG3", unique_code="TRIAL",
name="Program 3", name="One Week Trial",
price=300000.00, price=300000.00,
) )
...@@ -170,6 +169,8 @@ class CartTests(APITestCase): ...@@ -170,6 +169,8 @@ class CartTests(APITestCase):
response = self.client.get(url, request_params) response = self.client.get(url, request_params)
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
self.cart_3.transaction_status = 'pending' self.cart_3.transaction_status = 'pending'
self.cart_3.program_end_date = date.today() + \
timedelta(days=PROGRAM_DURATION[self.cart_3.program.unique_code])
self.assertEqual(response.data, CartSerializer(self.cart_3).data) self.assertEqual(response.data, CartSerializer(self.cart_3).data)
self.assertEqual(DietQuestionnaire.objects.count(), 1) self.assertEqual(DietQuestionnaire.objects.count(), 1)
self.assertEqual(DietQuestionnaire.objects.last().user, self.cart_3.user) self.assertEqual(DietQuestionnaire.objects.last().user, self.cart_3.user)
......
import json import json
import os import os
from datetime import timedelta, date
from rest_framework import viewsets, status from rest_framework import viewsets, status
from rest_framework.response import Response from rest_framework.response import Response
import requests import requests
from constants.transaction_status import TransactionStatus as TRANSACTION_STATUS from constants.transaction_status import TransactionStatus as TRANSACTION_STATUS
from constants.string_constants import CART_NOT_FOUND_MESSAGE from constants.string_constants import CART_NOT_FOUND_MESSAGE
from constants.program_duration import PROGRAM_DURATION
from dietela_program.serializers import DietelaProgramSerializer from dietela_program.serializers import DietelaProgramSerializer
from dietela_program.models import DietelaProgram from dietela_program.models import DietelaProgram
from diet_questionnaire.models import DietQuestionnaire from diet_questionnaire.models import DietQuestionnaire
...@@ -119,6 +121,8 @@ class MidtransRedirectionViewSet(viewsets.ViewSet): ...@@ -119,6 +121,8 @@ class MidtransRedirectionViewSet(viewsets.ViewSet):
status=status.HTTP_400_BAD_REQUEST) status=status.HTTP_400_BAD_REQUEST)
cart.transaction_status = transaction_status cart.transaction_status = transaction_status
cart.program_end_date = date.today() + timedelta(days=\
PROGRAM_DURATION[cart.program.unique_code])
cart.save() cart.save()
DietQuestionnaire.objects.create(user=cart.user) DietQuestionnaire.objects.create(user=cart.user)
......
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