Facebook
From Irwan, 3 Years ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 55
  1. import moment from 'moment';
  2. import uuidv4 from 'uuid/v4';
  3. import { isEmpty, pick } from 'lodash';
  4. import * as api from './utils/api.util.test';
  5. import {
  6.   initialTestSetup, badRequestResponse, checkCommonResponse, internalServerErrorResponse,
  7. } from './utils/helpers/common.helper';
  8. import {
  9.   checkAppointmentResponse, checkAppDoctor, checkUpdateNotes, cancelApp, createApp,
  10. } from './utils/helpers/appointment.helper';
  11. import { getPatientApp } from './utils/helpers/admission.helper';
  12. import { mySiloamAppointments } from '../variables/tableName.variable';
  13. import { channel } from '../variables/common.variable';
  14.  
  15. const env = process.env.NODE_ENV || 'test';
  16. const token = env === 'prodExt' ? initialTestSetup() : '';
  17.  
  18. describe('Appointments', async () => {
  19.   let params = {
  20.     name: 'ALBERT',
  21.     birth: '1989-01-25',
  22.     mr: 798084,
  23.     fromDate: moment.tz('Asia/Jakarta').format('YYYY-MM-DD'),
  24.     toDate: moment.tz('Asia/Jakarta').add(7, 'days').format('YYYY-MM-DD'),
  25.     isActiveOnly: true,
  26.     appDate: moment.tz('Asia/Jakarta').format('YYYY-MM-DD'),
  27.     hospitalId: '39764039-37b9-4176-a025-ef7b2e124ba4',
  28.     isWaitingList: false,
  29.     modifiedName: 'anil baswedan',
  30.     specialityId: '8646beb4-3cc4-4c62-bdd7-51529311bf11',
  31.     channelId: channel.BPJS,
  32.   };
  33.   const additionalPayload = {
  34.     userId: uuidv4(),
  35.     source: '127.0.0.1',
  36.     userName: 'Front Office Testing',
  37.   };
  38.   const endpoint = `/hospital/${params.hospitalId}`;
  39.   let appointment;
  40.  
  41.   before(async () => {
  42.     appointment = await getPatientApp({
  43.       attributes: [
  44.         'appointment_id',
  45.         `${mySiloamAppointments.TM_CONTACT}.name`,
  46.         `${mySiloamAppointments.TM_CONTACT}.birth_date`,
  47.         `${mySiloamAppointments.TM_CONTACT}->${mySiloamAppointments.TM_PATIENT}->${mySiloamAppointments.TX_PATIENT_HOSPITAL}s.medical_record_number`,
  48.         'appointment_date',
  49.         'hospital_id',
  50.         'modified_name',
  51.         'is_waiting_list',
  52.         'doctor_id',
  53.       ],
  54.       appDate: moment.tz('Asia/Jakarta').add(1, 'day').format('YYYY-MM-DD'),
  55.       patient: true,
  56.       patientHospital: true,
  57.       hospitalId: params.hospitalId,
  58.     });
  59.     if (isEmpty(appointment)) appointment = await createApp({ ...additionalPayload, ...params });
  60.     params = {
  61.       ...params,
  62.       doctorId: appointment.doctor_id,
  63.       fromDate: appointment.appointment_date,
  64.       toDate: moment(appointment.appointment_date, 'YYYY-MM-DD').add(7, 'day').format('YYYY-MM-DD'),
  65.       appDate: appointment.appointment_date,
  66.       name: String(appointment.name).substring(0, 10),
  67.       birth: appointment.birth_date,
  68.       mr: appointment.medical_record_number,
  69.       isActiveOnly: true,
  70.       hospital: appointment.hospital_id,
  71.       isWaitingList: appointment.is_waiting_list,
  72.       modifiedName: appointment.modified_name,
  73.       channelId: appointment.channel_id,
  74.     };
  75.   });
  76.  
  77.   describe('Successfull Scenario Testing', () => {
  78.     it('it should return of list appointment without filter', async () => {
  79.       const query = `?date=${params.appDate}`;
  80.       const res = await api.getAppointmentList(token, endpoint, query);
  81.       checkCommonResponse(res);
  82.       checkAppointmentResponse(res, pick(params, ['appDate']));
  83.       res.body.should.have.property('message').eql('List of appointment');
  84.     });
  85.  
  86.     it('it should return of list appointment with filter by name, birth, mr, doctor', async () => {
  87.       const query = `?name=${params.name}&birth=${params.birth}&mr=${params.mr}&doctor=${params.doctorId}`;
  88.       const uri = endpoint + query;
  89.       const res = await api.getAppointmentList(token, uri);
  90.       checkCommonResponse(res);
  91.       checkAppointmentResponse(res, pick(params, ['name', 'birth', 'mr', 'doctorId']));
  92.       res.body.should.have.property('message').eql('List of appointment');
  93.     });
  94.  
  95.     it('it should return of list appointment with filter by name, birth, mr', async () => {
  96.       const query = `?name=${params.name}&birth=${params.birth}&mr=${params.mr}`;
  97.       const uri = endpoint + query;
  98.       const res = await api.getAppointmentList(token, uri);
  99.       checkCommonResponse(res);
  100.       checkAppointmentResponse(res, pick(params, ['name', 'birth', 'mr']));
  101.       res.body.should.have.property('message').eql('List of appointment');
  102.     });
  103.  
  104.     it('it should return of list appointment with filter by name, birth', async () => {
  105.       const query = `?name=${params.name}&birth=${params.birth}`;
  106.       const uri = endpoint + query;
  107.       const res = await api.getAppointmentList(token, uri);
  108.       checkCommonResponse(res);
  109.       checkAppointmentResponse(res, pick(params, ['name', 'birth']));
  110.       res.body.should.have.property('message').eql('List of appointment');
  111.     });
  112.  
  113.     it('it should return of list appointment with filter by name', async () => {
  114.       const query = `?name=${params.name}`;
  115.       const uri = endpoint + query;
  116.       const res = await api.getAppointmentList(token, uri);
  117.       checkCommonResponse(res);
  118.       checkAppointmentResponse(res, pick(params, ['name']));
  119.       res.body.should.have.property('message').eql('List of appointment');
  120.     });
  121.  
  122.     it('it should return of list appointment with filter by doctor', async () => {
  123.       const query = `?doctor=${params.doctorId}`;
  124.       const uri = endpoint + query;
  125.       const res = await api.getAppointmentList(token, uri);
  126.       checkCommonResponse(res);
  127.       checkAppointmentResponse(res, pick(params, ['doctorId']));
  128.       res.body.should.have.property('message').eql('List of appointment');
  129.     });
  130.  
  131.     it('it should return of list appointment with filter by mr', async () => {
  132.       const query = `?mr=${params.mr}`;
  133.       const uri = endpoint + query;
  134.       const res = await api.getAppointmentList(token, uri);
  135.       checkCommonResponse(res);
  136.       checkAppointmentResponse(res, pick(params, ['mr']));
  137.       res.body.should.have.property('message').eql('List of appointment');
  138.     });
  139.  
  140.     it('it should return of list appointment with filter by birth date', async () => {
  141.       const query = `?birth=${params.birth}`;
  142.       const uri = endpoint + query;
  143.       const res = await api.getAppointmentList(token, uri);
  144.       checkCommonResponse(res);
  145.       checkAppointmentResponse(res, pick(params, ['birth']));
  146.       res.body.should.have.property('message').eql('List of appointment');
  147.     });
  148.  
  149.     it('it should return of list appointment with from date, to date', async () => {
  150.       const query = `?fromDate=${params.fromDate}&toDate=${params.toDate}`;
  151.       const uri = endpoint + query;
  152.       const res = await api.getAppointmentList(token, uri);
  153.       checkCommonResponse(res);
  154.       checkAppointmentResponse(res, pick(params, ['fromDate', 'toDate']));
  155.       res.body.should.have.property('message').eql('List of appointment');
  156.     });
  157.  
  158.     it('it should return of list appointment only for active appointment', async () => {
  159.       const query = `?isActiveOnly=${params.isActiveOnly}`;
  160.       const uri = endpoint + query;
  161.       const res = await api.getAppointmentList(token, uri);
  162.       checkCommonResponse(res);
  163.       checkAppointmentResponse(res, pick(params, ['isActiveOnly']));
  164.       res.body.should.have.property('message').eql('List of appointment');
  165.     });
  166.  
  167.     it('it should return of list appointment with filter waiting list', async () => {
  168.       const query = `?isWaitingList=${params.isWaitingList}`;
  169.       const uri = endpoint + query;
  170.       const res = await api.getAppointmentList(token, uri);
  171.       checkCommonResponse(res);
  172.       checkAppointmentResponse(res, pick(params, ['isWaitingList']));
  173.       res.body.should.have.property('message').eql('List of appointment');
  174.     });
  175.  
  176.     it('it should return of list appointment with filter modified name', async () => {
  177.       const query = `?modifiedName=${params.modifiedName}`;
  178.       const uri = endpoint + query;
  179.       const res = await api.getAppointmentList(token, uri);
  180.       checkCommonResponse(res);
  181.       checkAppointmentResponse(res, pick(params, ['modifiedName']));
  182.       res.body.should.have.property('message').eql('List of appointment');
  183.       await cancelApp(appointment, additionalPayload);
  184.     });
  185.  
  186.     it('it should return of list appointment with filter channel ID & exclude true', async () => {
  187.       const query = `?channelId=${params.channelId}&exclude=true`;
  188.       const uri = endpoint + query;
  189.       const res = await api.getAppointmentList(token, uri);
  190.       checkCommonResponse(res);
  191.       checkAppointmentResponse(res, { ...pick(params, ['channelId']), exclude: true });
  192.       res.body.should.have.property('message').eql('List of appointment');
  193.       await cancelApp(appointment, additionalPayload);
  194.     });
  195.  
  196.     it('it should return of list appointment with filter channel ID & exclude false', async () => {
  197.       const query = `?channelId=${params.channelId}&exclude=false`;
  198.       const uri = endpoint + query;
  199.       const res = await api.getAppointmentList(token, uri);
  200.       checkCommonResponse(res);
  201.       checkAppointmentResponse(res, { ...pick(params, ['channelId']), exclude: false });
  202.       res.body.should.have.property('message').eql('List of appointment');
  203.       await cancelApp(appointment, additionalPayload);
  204.     });
  205.   });
  206.  
  207.   describe('Failed Scenario Testing', () => {
  208.     it('it should failed when give invalid doctor id guid', async () => {
  209.       const query = '?doctor=87329-hdkshd';
  210.       const uri = endpoint + query;
  211.       const res = await api.getAppointmentList(token, uri);
  212.       badRequestResponse(res);
  213.     });
  214.  
  215.     it('it should failed when give invalid medical record', async () => {
  216.       const query = '?mr=hdkshd';
  217.       const uri = endpoint + query;
  218.       const res = await api.getAppointmentList(token, uri);
  219.       badRequestResponse(res);
  220.     });
  221.  
  222.     it('it should failed when give invalid birthdate', async () => {
  223.       const query = '?birth=27-05-1996';
  224.       const uri = endpoint + query;
  225.       const res = await api.getAppointmentList(token, uri);
  226.       badRequestResponse(res);
  227.     });
  228.   });
  229. });