import { G } from "react-native-svg";
import { Achievement } from "../../src/architecture/business_layer/Achievement";
import { Guest } from "../../src/architecture/business_layer/Guest";
import { CBTReportContext } from "../../src/architecture/business_layer/modules/CBTReportContext";
import { ActiveFill } from "../../src/architecture/business_layer/modules/ReportStrategies/ActiveFill";
import { bodyParts, BodyPartSelection } from "../../src/architecture/business_layer/modules/ReportStrategies/BodyPartSelection";
import { Camera } from "../../src/architecture/business_layer/modules/ReportStrategies/Camera";
import { makeAchievements } from "../../src/architecture/business_layer/TranslatingData";
import { DType, getValueofCBTReport, getValueofAchievement, wipe_guest } from "../../src/architecture/data_access_layer/local_storage";
import { makeActiveFill, makeBodyPartSelection } from "../../src/architecture/service_layer/types";
export const sleep = async (waitTime: number) =>
new Promise(resolve =>
setTimeout(resolve, waitTime));
const valid_date = new Date(Date.now()-86400000);
const invalid_date = new Date(Date.now() + 100000);
const good_event = "good";
const feeling_good_event = "feeling good";
const valid_body_part = "hand";
const valid_body_part_selection = valid_body_part;
const active_fill_emotion = [{emoji:"hello",name:"plzz"}];
const thought = "my";
const response = "world";
const fill2 = new ActiveFill("feeling good", [],"leg", "my", "world");
const fill3 = new ActiveFill("feeling good", [],"head");
const previousMonthDate = new Date(Date.now()-(86400000*1000));
const previousMonthReport = new ActiveFill("feeling good", [],"head", "???", "YEAH", -1, previousMonthDate);
const emotiobnstring ="yoyo";
const fill1 = new ActiveFill("feeling good", [],"head", "my", "world");
const cameraContext = new Camera("image1", new Date(Date.now()));
const date1 = new Date(Date.now());
const formatdate = new Date(`${new Date().getFullYear()}/${new Date().getMonth()+1}`);
const changeCreationDate = (report: ActiveFill, creationDate: Date) => new ActiveFill(report.getEvent(), report.getEmotion(), report.getBodyPart()?.getPart(), report.getthought(), report.getResponse(), report.getIndex(), report.getEventDate(), creationDate);
describe("Guest add reports tests", () => {
beforeEach(async () => await wipe_guest());
test('checking add report with one report', async () =>{
const date = new Date(Date.now());
const report = fill1;
const guest = new Guest();
await guest.addReport(report);
expect(guest.reports.getReportAmount()).toBe(1);
expect(guest.reports.getReport(0)).toBe(report);
});
test('checking add report with two report', async () =>{
const date = new Date(Date.now());
const report1 = fill1;
const report2 = fill2;
const guest = new Guest();
await guest.addReport(report1);
expect(guest.reports.getReportAmount()).toBe(1);
await guest.addReport(report2);
expect(guest.reports.getReportAmount()).toBe(2);
expect(guest.reports.getReport(0)).toBe(report1);
expect(guest.reports.getReport(1)).toBe(report2);
});
test('checking add report with two report', async () =>{
const date = new Date(Date.now());
const report1 = fill1;
const report2 = fill2;
const guest = new Guest();
await guest.addReport(report1);
expect(guest.reports.getReportAmount()).toBe(1);
await guest.addReport(report2);
expect(guest.reports.getReportAmount()).toBe(2);
expect(guest.reports.getReport(0)).toBe(report1);
expect(guest.reports.getReport(1)).toBe(report2);
});
test('checking add report with camera report', async () =>{
const date = new Date(Date.now());
const report1 = cameraContext;
const guest = new Guest();
await guest.addReport(report1);
expect(guest.reports.getReportAmount()).toBe(1);
expect(guest.reports.getReport(0)).toBe(report1);
});
});
describe("Paitent create reports tests", () => {
beforeEach(async () => await wipe_guest());
test('checking create report with good data', async () =>{
const date = new Date(Date.now());
// const report = makeActiveFill(date, feeling_good_event, active_fill_emotion, thought, response);
const guest = new Guest();
await guest.createCBTReportActiveFill(date, feeling_good_event, active_fill_emotion, valid_body_part, thought, response);
expect(guest.reports.getReportAmount()).toBe(1);
});
test('checking create report with bad event data', async () =>{
const date = new Date(Date.now());
const event = "";
// const report = makeActiveFill(date, event, active_fill_emotion, thought, response);
const guest = new Guest()
await expect(()=> guest.createCBTReportActiveFill(date, event, active_fill_emotion,valid_body_part, thought, response)).rejects.toThrow(ActiveFill.emptyEventError);
expect(guest.reports.getReportAmount()).toBe(0);
});
test('checking create report with wrong date', async () =>{
const date = new Date(Date.now()+100000);
const report = makeActiveFill(0,invalid_date, feeling_good_event, active_fill_emotion,valid_body_part, thought, response);
const guest = new Guest()
await expect(()=> guest.createCBTReportActiveFill(invalid_date, feeling_good_event, active_fill_emotion,valid_body_part, thought, response)).rejects.toThrow(CBTReportContext.futureDateError);
expect(guest.reports.getReportAmount()).toBe(0);
});
test('checking create report with only data', async () =>{
const date = new Date(Date.now());
const guest = new Guest();
await guest.createCBTReportActiveFill(date, good_event);
expect(guest.reports.getReportAmount()).toBe(1);
});
test('checking create report with two data', async () =>{
const date = new Date(Date.now());
const report = makeActiveFill(0,date, good_event);
const guest = new Guest();
await guest.createCBTReportActiveFill(date, good_event);
expect(guest.reports.getReportAmount()).toBe(1);
const report2 = makeActiveFill(0, date, good_event, active_fill_emotion);
await guest.createCBTReportActiveFill(date, good_event, active_fill_emotion);
expect(guest.reports.getReportAmount()).toBe(2);
});
test('checking create report with body part', async () =>{
const date = new Date(Date.now());
// const report = makeBodyPartSelection(date, good_event, valid_body_part);
const guest = new Guest();
await guest.createCBTReportActiveFill(date, good_event,[],valid_body_part);
expect(guest.reports.getReportAmount()).toBe(1);
});
test('checking create report with wrong date', async () =>{
const date = new Date(Date.now()+100000);
// const report = makeBodyPartSelection(date, good_event, valid_body_part);
const guest = new Guest();
await expect(() => guest.createCBTReportActiveFill(date, good_event, [],valid_body_part)).rejects.toThrow(CBTReportContext.futureDateError);
expect(guest.reports.getReportAmount()).toBe(0);
});
test('checking create two reports', async () =>{
const date = new Date(Date.now());
const bp = "hand";
const guest = new Guest();
await guest.createCBTReportActiveFill(date,good_event,[],bp);
expect(guest.reports.getReportAmount()).toBe(1);
await guest.createCBTReportActiveFill(date,good_event,[],"hand",thought,response);
expect(guest.reports.getReportAmount()).toBe(2);
});
});
describe("Guest remove report tests", () => {
beforeEach(async () => await wipe_guest());
test('checking add report with and remove it', async () =>{
const date = new Date(Date.now());
const fill = new ActiveFill("feeling good", [], valid_body_part_selection, "my", "world");
const report = fill;
const guest = new Guest();
await guest.addReport(report);
expect(guest.reports.getReportAmount()).toBe(1);
expect(guest.reports.getReport(0)).toBe(report);
guest.removeReportbyIndex(0);
expect(guest.reports.getReportAmount()).toBe(0);
});
test('checking add report with and remove wiyth wrong index', async () =>{
const date = new Date(Date.now());
const fill = new ActiveFill("feeling good", [],valid_body_part_selection, "my", "world");
const report = fill;
const guest = new Guest();
await guest.addReport(report)
expect(guest.reports.getReportAmount()).toBe(1);
expect(guest.reports.getReport(0)).toBe(report);
const ans = guest.reports.getReport(1);
expect(ans).toBe(undefined);
await expect(()=>guest.removeReportbyIndex(1)).rejects.toThrow(Guest.outofReportssBoundsError);
expect(guest.reports.getReportAmount()).toBe(1);
});
test('checking add report with and remove with wrong index', async () =>{
const date = new Date(Date.now());
const fill = new ActiveFill("feeling good",[],valid_body_part_selection, "my", "world");
const report = fill;
const guest = new Guest()
await guest.addReport(report)
expect(guest.reports.getReportAmount()).toBe(1);
expect(guest.reports.getReport(0)).toBe(report);
await expect(()=>guest.removeReportbyIndex(1)).rejects.toThrow(Guest.outofReportssBoundsError);
expect(guest.reports.getReportAmount()).toBe(1);
});
test('checking add report with and remove with two items', async () =>{
const report1 = fill1;
const date2 = new Date(Date.now());
const report2 = fill2;
const guest = new Guest();
await guest.addReport(report1);
expect(guest.reports.getReportAmount()).toBe(1);
await guest.addReport(report2);
expect(guest.reports.getReportAmount()).toBe(2);
expect(guest.reports.getReport(0)).toBe(report1);
expect(guest.reports.getReport(1)).toBe(report2);
guest.removeReportbyIndex(0);
expect(guest.reports.getReportAmount()).toBe(1);
expect(guest.reports.getReport(1)).toBe(report2);
});
test('checking add report with and remove with two items one good second out of range', async () =>{
const report1 = fill1;
const date2 = new Date(Date.now()-100);
const report2 = fill2;
const guest = new Guest();
await guest.addReport(report1);
expect(guest.reports.getReportAmount()).toBe(1);
await guest.addReport(report2);
expect(guest.reports.getReportAmount()).toBe(2);
expect(guest.reports.getReport(0)).toBe(report1);
expect(guest.reports.getReport(1)).toBe(report2);
await guest.removeReportbyIndex(0);
await expect(()=>guest.removeReportbyIndex(0)).rejects.toThrow(Guest.outofReportssBoundsError);
expect(guest.reports.getReportAmount()).toBe(1);
expect(guest.reports.getReport(1)).toBe(report2);
});
test('checking add report and removing camera report', async () =>{
const report1 = fill1;
const date2 = new Date(Date.now()-100);
const report2 = fill2;
const guest = new Guest();
await guest.addReport(report1);
expect(guest.reports.getReportAmount()).toBe(1);
await guest.addReport(report2);
expect(guest.reports.getReportAmount()).toBe(2);
expect(guest.reports.getReport(0)).toBe(report1);
expect(guest.reports.getReport(1)).toBe(report2);
guest.removeReportbyIndex(0)
await expect(()=>guest.removeReportbyIndex(0)).rejects.toThrow(Guest.outofReportssBoundsError);
expect(guest.reports.getReportAmount()).toBe(1);
expect(guest.reports.getReport(1)).toBe(report2);
});
test('checking remove report of camera', async () =>{
const date = new Date(Date.now());
const report = cameraContext;
const guest = new Guest();
await guest.addReport(report);
expect(guest.reports.getReportAmount()).toBe(1);
expect(guest.reports.getReport(0)).toBe(report);
expect(()=>guest.removeReportbyIndex(0)).not.toThrow();
expect(guest.reports.getReportAmount()).toBe(0);
});
});
describe("Guest Summary tests", () => {
test('checking getsummary with one report', async () =>{
const date = new Date(Date.now());
const fill = new ActiveFill("feeling good", [],valid_body_part_selection, "my", "world");
const report = fill;
const guest = new Guest()
await guest.addReport(report)
expect(guest.reports.getReportAmount()).toBe(1);
// expect(guest.getSummary()).toBe(report.getSummary());
});
test('checking get summary with two reports', async () =>{
const report1 = fill1;
const date2 = new Date(Date.now());
const report2 =fill2;
const guest = new Guest();
await guest.addReport(report1);
expect(guest.reports.getReportAmount()).toBe(1);
await guest.addReport(report2);
expect(guest.reports.getReportAmount()).toBe(2);
// expect(guest.getSummary())
// .toBe(report1.getSummary()+"\n"+report2.getSummary());
});
test('checking get summary with no reports', () =>{
const guest = new Guest();
expect(guest.reports.getReportAmount()).toBe(0);
// expect("")
// .toBe(guest.getSummary());
});
});
describe("Guest Storage tests", () => {
beforeEach(async () => await wipe_guest());
test('checking getsummary Storage with one report', async () =>{
const date = new Date(Date.now());
const fill = new ActiveFill("feeling good", [],valid_body_part_selection, "my", "world");
const report = fill;
const guest = new Guest()
await guest.addReport(report)
expect(guest.reports.getReportAmount()).toBe(1);
// expect(guest.getSummary()).toBe(report.getSummary());
let storedreport = await getValueofCBTReport({"UserName": "Guest","index": "0", "DataType":DType.CBTReportContext})
if(storedreport!= undefined)
{
expect(storedreport.tag).toBe("activeFill");
// expect(storedreport.getSummary())
// .toBe(report.getSummary());
}
});
test('checking get summary Storage with two reports', async () =>{
const report1 = fill1;
const date2 = new Date(Date.now()-100);
const report2 = fill2;
const guest = new Guest();
await guest.addReport(report1);
expect(guest.reports.getReportAmount()).toBe(1);
await guest.addReport(report2);
expect(guest.reports.getReportAmount()).toBe(2);
// expect(guest.getSummary())
// .toBe(report1.getSummary()+"\n"+report2.getSummary());
let storedreport1 = await getValueofCBTReport({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
if(storedreport1!= undefined)
{
expect(storedreport1.tag).toBe("activeFill");
// expect(storedreport1.getSummary())
// .toBe(report1.getSummary());
}
let storedreport2 = await getValueofCBTReport({"UserName": "Guest","index":"1", "DataType":DType.CBTReportContext})
if(storedreport2!= undefined)
{
expect(storedreport2.tag).toBe("activeFill");
// expect(storedreport2.getSummary())
// .toBe(report2.getSummary());
}
});
test('checking delete Storage with ', async () =>{
const report1 = fill1;
const date2 = new Date(Date.now()-100);
const report2 = fill2;
const guest = new Guest();
await guest.addReport(report1);
expect(guest.reports.getReportAmount()).toBe(1);
await guest.addReport(report2);
expect(guest.reports.getReportAmount()).toBe(2);
// expect(guest.getSummary())
// .toBe(report1.getSummary()+"\n"+report2.getSummary());
let storedreport1 = await getValueofCBTReport({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
if(storedreport1!= undefined)
{
expect(storedreport1.tag).toBe("activeFill");
// expect(storedreport1.getSummary())
// .toBe(report1.getSummary());
}
let storedreport2 = await getValueofCBTReport({"UserName": "Guest","index":"1", "DataType":DType.CBTReportContext})
if(storedreport2!= undefined)
{
expect(storedreport2.tag).toBe("activeFill");
// expect(storedreport2.getSummary())
// .toBe(report2.getSummary());
}
await guest.removeReportbyIndex(1);
await expect(getValueofCBTReport({"UserName": "Guest","index":"1", "DataType":DType.CBTReportContext})).resolves.toBeUndefined();
let storedreportmore1 = await getValueofCBTReport({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
if(storedreportmore1!= undefined)
{
expect(storedreportmore1.tag).toBe("activeFill");
// expect(storedreportmore1.getSummary())
// .toBe(report1.getSummary());
}
});
test('checking create report to Storage with one report', async () =>{
const date = new Date(Date.now());
const guest = new Guest()
await guest.createCBTReportActiveFill(date,good_event,[],valid_body_part);
expect(guest.reports.getReportAmount()).toBe(1);
let storedreport = await getValueofCBTReport({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
if(storedreport!= undefined)
{
expect(storedreport.tag).toBe("activeFill");
expect(guest.reports.getReport(0)).toBeDefined();
// expect(storedreport.getSummary())
// .toBe(guest.reports.get(0)?.getSummary());
}
});
test('checking create report to Storage with two reports', async () =>{
const date1 = new Date(Date.now());
const bp = "hand";
const guest = new Guest()
await guest.createCBTReportActiveFill(date1,good_event,[],bp);
expect(guest.reports.getReportAmount()).toBe(1);
await sleep(2000);
const date2 = new Date(Date.now());
await guest.createCBTReportActiveFill(date2,good_event,[],"hand",thought,response);
expect(guest.reports.getReportAmount()).toBe(2);
let storedreport = await getValueofCBTReport({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
if(storedreport!= undefined)
{
expect(storedreport.tag).toBe("activeFill");
expect(guest.reports.getReport(0)).toBeDefined();
// expect(storedreport.getSummary()).toBe(guest.reports.get(0)?.getSummary());
}
let storedreport2 = await getValueofCBTReport({"UserName": "Guest","index":"1", "DataType":DType.CBTReportContext})
if(storedreport2!= undefined)
{
expect(storedreport2.tag).toBe("activeFill");
expect(guest.reports.getReport(1)).toBeDefined();
// expect(storedreport2.getSummary())
// .toBe(guest.reports.get(1)?.getSummary());
}
});
beforeEach( async ()=>await wipe_guest())
test('checking get all from Storage with one reports', async () =>{
var guest = new Guest()
await guest.createCBTReportActiveFill(date1,good_event,[],valid_body_part);
expect(guest.reports.getReportAmount()).toBe(1);
let storedreport = await getValueofCBTReport({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
if(storedreport!= undefined)
{
expect(storedreport.tag).toBe("activeFill");
expect(guest.reports.getReport(0)).toBeDefined();
// expect(storedreport.getSummary())
// .toBe(guest.reports.get(0)?.getSummary());
}
guest = new Guest();
expect(guest.reports.getReportAmount()).toBe(0);
await guest.getAllCBTReportsFromStorage();
expect(guest.reports.getReportAmount()).toBe(1);
if(storedreport!= undefined)
{
expect(storedreport.tag).toBe("activeFill");
expect(guest.reports.getReport(0)).toBeDefined();
// expect(storedreport.getSummary())
// .toBe(guest.reports.get(0)?.getSummary());
}
});
test('checking get all Storage with two report', async () =>{
const bp = "hand";
var guest = new Guest()
await guest.createCBTReportActiveFill(date1,good_event,[],bp);
expect(guest.reports.getReportAmount()).toBe(1);
const date2 = new Date(Date.now()-100);
await guest.createCBTReportActiveFill(date2,good_event,[],"head",thought,response);
expect(guest.reports.getReportAmount()).toBe(2);
let storedreport = await getValueofCBTReport({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
expect(storedreport).toBeDefined();
if(storedreport!= undefined)
{
expect(storedreport.tag).toBe("activeFill");
expect(guest.reports.getReport(0)).toBeDefined();
// expect(storedreport.getSummary())
// .toBe(guest.reports.get(0)?.getSummary());
}
let storedreport2 = await getValueofCBTReport({"UserName": "Guest","index":"1", "DataType":DType.CBTReportContext})
expect(storedreport2).toBeDefined();
if(storedreport2!= undefined)
{
expect(storedreport2.tag).toBe("activeFill");
expect(guest.reports.getReport(1)).toBeDefined();
// expect(storedreport2.getSummary())
// .toBe(guest.reports.get(1)?.getSummary());
}
guest = new Guest();
expect(guest.reports.getReportAmount()).toBe(0);
await guest.getMonthlyReports(date1);
expect(guest.reports.getReportAmount()).toBe(2);
if(storedreport!= undefined)
{
expect(storedreport.tag).toBe("activeFill");
expect(guest.reports.getReport(0)).toBeDefined();
// expect(storedreport.getSummary())
// .toBe(guest.reports.get(0)?.getSummary());
}
if(storedreport2!= undefined)
{
expect(storedreport2.tag).toBe("activeFill");
expect(guest.reports.getReport(1)).toBeDefined();
// expect(storedreport2.getSummary())
// .toBe(guest.reports.get(1)?.getSummary());
}
});
test('checking create camera report to Storage with one report', async () =>{
const guest = new Guest();
await guest.addReport(cameraContext);
expect(guest.reports.getReportAmount()).toBe(1);
let storedreport = await getValueofCBTReport({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
if(storedreport!= undefined)
{
expect(storedreport.tag).toBe("camera");
expect(guest.reports.getReport(0)).toBeDefined();
// expect(storedreport.getSummary())
// .toBe(guest.reports.get(0)?.getSummary());
}
});
});
describe("Guest getReports tests", () => {
beforeEach(async () => await wipe_guest());
test('checking getReports with one report', async () =>{
const date = new Date(Date.now());
const fill = new ActiveFill("feeling good",[],valid_body_part_selection, "my", "world");
const report = fill;
const guest = new Guest()
await guest.addReport(report)
expect(guest.reports.getReportAmount()).toBe(1);
expect(guest.reports.getReport(0)).toBe(report);
const monthlyReports = await guest.getMonthlyReports(formatdate);
expect(monthlyReports[0]).toBe(report);
});
test('checking getReports with two report', async () =>{
const report1 = fill1;
const date2 = new Date(Date.now()-86400000);
const report2 = fill2;
const guest = new Guest();
await guest.addReport(report1);
expect(guest.reports.getReportAmount()).toBe(1);
await guest.addReport(report2);
expect(guest.reports.getReportAmount()).toBe(2);
const monthlyReports = await guest.getMonthlyReports(formatdate);
expect(monthlyReports[0]).toBe(report1);
expect(monthlyReports[1]).toBe(report2);
});
test('checking getReports with two report and not one', async () =>{
const report1 = fill1;
const date2 = new Date(Date.now()-86400000);
const report2 = fill2;
const guest = new Guest();
await guest.addReport(report1);
await guest.addReport(report2);
await guest.addReport(previousMonthReport);
expect(guest.reports.getReportAmount()).toBe(3);
const monthlyReports = await guest.getMonthlyReports(formatdate);
expect(monthlyReports[0]).toBe(report1);
expect(monthlyReports[1]).toBe(report2);
expect(monthlyReports.length).toBe(2);
});
});
describe("Guest getReportbyspecificdate tests", () => {
beforeEach(async () => await wipe_guest());
test('checking getReportbyspecificdate with one report', async () =>{
const formatdate = new Date("2023/01");
const date = new Date(Date.now());
const fill = new ActiveFill("feeling good", [],valid_body_part_selection, "my", "world");
const report = fill;
const guest = new Guest();
await guest.addReport(report);
expect(guest.reports.getReportAmount()).toBe(1);
expect(guest.reports.getReport(0)).toBe(report);
expect(guest.reports.getReportsByMonth(date)).toContain(report);
});
test('checking getReportbyspecificdate with two report one good', async () =>{
const formatdate = new Date("2023/01");
const report1 = fill1;
const date2 = new Date(Date.now()-86400000);
const report2 =fill2;
const guest = new Guest();
await guest.addReport(report1);
expect(guest.reports.getReportAmount()).toBe(1);
await guest.addReport(report2);
expect(guest.reports.getReportAmount()).toBe(2);
expect(guest.reports.getReportsByMonth(date1)).toContain(report1);
});
});
describe("Guest add reports tests", () => {
beforeEach(async () => await wipe_guest());
test('checking add report with one report', async () =>{
const date = new Date(Date.now());
const fill = new ActiveFill("feeling good", [],valid_body_part_selection, "my", "world");
const report = fill;
const guest = new Guest()
await guest.addReport(report)
expect(guest.reports.getReportAmount()).toBe(1);
expect(guest.reports.getReport(0)).toBe(report);
});
test('checking add report with two report', async () =>{
const date = new Date(Date.now());
const report1 = fill1;
const report2 = fill2;
const guest = new Guest();
await guest.addReport(report1);
expect(guest.reports.getReportAmount()).toBe(1);
await guest.addReport(report2);
expect(guest.reports.getReportAmount()).toBe(2);
expect(guest.reports.getReport(0)).toBe(report1);
expect(guest.reports.getReport(1)).toBe(report2);
});
});
describe("Guest check achievements tests", () => {
beforeEach(async () => await wipe_guest());
test('checking check achievements with one data', async () =>{
const date = new Date(Date.now());
const guest = new Guest()
await guest.createCBTReportActiveFill(date,feeling_good_event,active_fill_emotion,thought,response);
expect(guest.reports.getReportAmount()).toBe(1);
const achievements = guest.getAchievements();
expect(achievements?.rewardFillReport).toBe(1);
expect(achievements?.rewardFillReportInaRow).toBe(1);
});
test('checking check achievements with three good data', async () =>{
const date = new Date();
const guest = new Guest();
const date2 = new Date();
date2.setDate(date2.getDate() - 1);
const date3 = new Date();
date3.setDate(date3.getDate() - 2);
const fill3 = new ActiveFill("feeling good", [],valid_body_part_selection);
var achievements = guest.getAchievements();
expect(achievements?.rewardFillReport).toBe(0);
expect(achievements?.streakFillReport).toBe(0);
expect(achievements?.rewardFillReportInaRow).toBe(0);
const report2 = changeCreationDate(fill2, date2);
const report3 = changeCreationDate(fill3, date3);
await guest.addReport(report3);
achievements = guest.getAchievements();
expect(achievements?.rewardFillReport).toBe(1);
expect(achievements?.streakFillReport).toBe(1);
expect(achievements?.rewardFillReportInaRow).toBe(1);
await guest.addReport(report2);
achievements = guest.getAchievements();
expect(achievements?.rewardFillReport).toBe(2);
expect(achievements?.streakFillReport).toBe(2);
expect(achievements?.rewardFillReportInaRow).toBe(2);
await guest.createCBTReportActiveFill(date,feeling_good_event,active_fill_emotion,thought,response);
achievements = guest.getAchievements();
expect(achievements?.rewardFillReport).toBe(3);
expect(achievements?.streakFillReport).toBe(3);
expect(achievements?.rewardFillReportInaRow).toBe(3);
});
test('checking check achievements with three good data two in same day', async () =>{
const date = new Date(Date.now());
const guest = new Guest()
const date2 = new Date(Date.now()-86300000);
const date3 = new Date(Date.now()-(86400000));
const fill3 = new ActiveFill("feeling good", [], "hand");
const report2 = changeCreationDate(fill2, date2);
const report3 = changeCreationDate(fill3, date3);
await guest.addReport(report3);
await guest.addReport(report2);
await guest.createCBTReportActiveFill(date,feeling_good_event,active_fill_emotion,thought,response);
const achievements = guest.getAchievements();
expect(achievements?.rewardFillReport).toBe(3);
expect(achievements?.rewardFillReportInaRow).toBe(2);
});
});
describe("Guest check achievements Storage tests", () => {
beforeEach(async () => await wipe_guest());
test('checking check achievements Storage with one data', async () =>{
const date = new Date(Date.now());
const guest = new Guest()
await guest.createCBTReportActiveFill(date,feeling_good_event,active_fill_emotion,thought,response);
expect(guest.reports.getReportAmount()).toBe(1);
const achievements = guest.getAchievements();
expect(makeAchievements( await getValueofAchievement("Guest"))).toStrictEqual(guest.getAchievements());
});
test('checking check achievements Storage with three good data', async () =>{
const date = new Date(Date.now());
const guest = new Guest();
const date2 = new Date(Date.now()-86400000);
const date3 = new Date(Date.now()-(86400000*2));
const fill3 = new ActiveFill("feeling good",[], valid_body_part_selection);
const report2 = changeCreationDate(fill2, date2);
const report3 = changeCreationDate(fill3, date3);
await guest.addReport(report3);
expect(makeAchievements( await getValueofAchievement("Guest"))).toStrictEqual(guest.getAchievements());
await guest.addReport(report2);
expect(makeAchievements( await getValueofAchievement("Guest"))).toStrictEqual(guest.getAchievements());
await guest.createCBTReportActiveFill(date,feeling_good_event,active_fill_emotion,thought,response);
const achievements = guest.getAchievements();
expect(makeAchievements( await getValueofAchievement("Guest"))).toStrictEqual(guest.getAchievements());
expect( (makeAchievements( await getValueofAchievement("Guest"))).rewardFillReportInaRow).toStrictEqual(3);
expect( (makeAchievements( await getValueofAchievement("Guest"))).rewardFillReport).toStrictEqual(3);
});
test('checking check achievements Storage with three good data two in same day', async () =>{
const date = new Date(Date.now());
const guest = new Guest()
const date2 = new Date(Date.now()-86300000);
const date3 = new Date(Date.now()-(86400000));
const fill3 = new ActiveFill("feeling good",[], valid_body_part_selection);
const report2 = changeCreationDate(fill2, date2);
const report3 = changeCreationDate(fill3, date3);
await guest.addReport(report3);
expect(makeAchievements( await getValueofAchievement("Guest"))).toStrictEqual(guest.getAchievements());
await guest.addReport(report2);
expect(makeAchievements( await getValueofAchievement("Guest"))).toStrictEqual(guest.getAchievements());
await guest.createCBTReportActiveFill(date,feeling_good_event,active_fill_emotion,thought,response);
expect(makeAchievements( await getValueofAchievement("Guest"))).toStrictEqual(guest.getAchievements());
expect( (makeAchievements( await getValueofAchievement("Guest"))).rewardFillReportInaRow).toStrictEqual(2);
expect( (makeAchievements( await getValueofAchievement("Guest"))).rewardFillReport).toStrictEqual(3);
});
test('checking getachievementsfromStorage with three good data two in same day', async () =>{
const date = new Date(Date.now());
const guest = new Guest()
const date2 = new Date(Date.now()-86300000);
const report2 = changeCreationDate(fill2, date2);
const date3 = new Date(Date.now()-(86400000));
const fill3 = new ActiveFill("feeling good", [], valid_body_part_selection);
const report3 = changeCreationDate(fill3, date3);
await guest.addReport(report3);
expect(makeAchievements( await getValueofAchievement("Guest"))).toStrictEqual(guest.getAchievements());
await guest.addReport(report2);
expect(makeAchievements( await getValueofAchievement("Guest"))).toStrictEqual(guest.getAchievements());
await guest.createCBTReportActiveFill(date,feeling_good_event,active_fill_emotion,thought,response);
expect(makeAchievements( await getValueofAchievement("Guest"))).toStrictEqual(guest.getAchievements());
expect( (makeAchievements( await getValueofAchievement("Guest"))).rewardFillReportInaRow).toStrictEqual(2);
expect( (makeAchievements( await getValueofAchievement("Guest"))).rewardFillReport).toStrictEqual(3);
guest.achievements = new Achievement();
await guest.getAchievementsFromStorageTest();
expect(guest.achievements.rewardFillReportInaRow).toStrictEqual(2);
expect(guest.achievements.rewardFillReport).toStrictEqual(3);
});
});
describe("Guest draft tests", () => {
beforeEach(async () => await wipe_guest());
test("create draft and retrieve it", () => {
const guest = new Guest();
guest.createCBTDraftActiveFill(date1, good_event, active_fill_emotion,valid_body_part, thought, response);
const fill = new ActiveFill(good_event,active_fill_emotion,valid_body_part_selection, thought, response);
const report = new ActiveFill(good_event,active_fill_emotion,valid_body_part_selection, thought, response, -1, date1, guest.getDraft()?.getCreationDate());
expect(guest.getDraft()).toStrictEqual(report);
});
test("create draft and retrieve it from memory", async () => {
const guest = new Guest();
guest.createCBTDraftActiveFill(date1, good_event, active_fill_emotion,valid_body_part, thought, response);
const draft = guest.draft;
const bad_fill = new ActiveFill(feeling_good_event, active_fill_emotion,valid_body_part_selection, thought, response);
guest.draft = bad_fill;
await guest.getDraftFromStorageTest();
expect(guest.getDraft()).toStrictEqual(draft);
});
});