Unit Testing: Guest - CBTYoung/Documentation GitHub Wiki

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 { DType, getValue, getValueofAchievements, 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 = new BodyPartSelection(bodyParts.hand);
    const active_fill_emotion = [{emoji:"hello",name:"plzz"}];
    const thought = "my";
    const response = "world";
    const fill2 = new ActiveFill("feeling good", [],new BodyPartSelection(bodyParts["leg"]), "my", "world");
    const fill3 = new ActiveFill("feeling good", [],new BodyPartSelection(bodyParts["head"]));
    const emotiobnstring ="yoyo";
    const fill1 = new ActiveFill("feeling good", [],new BodyPartSelection(bodyParts["head"]), "my", "world");
    const date1 = new Date(Date.now());

    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 = new CBTReportContext(date, fill1);
            const guest = new Guest();
            await guest.addReport(report);
            expect(guest.reports.size).toBe(1);
            expect(guest.reports.get(0)).toBe(report);
        });

        test('checking add report with two report', async () =>{
            const date = new Date(Date.now());
            const report1 = new CBTReportContext(date, fill1);
            const report2 = new CBTReportContext(date, fill2);
            const guest = new Guest();
            await guest.addReport(report1);
            expect(guest.reports.size).toBe(1);
            await guest.addReport(report2);
            expect(guest.reports.size).toBe(2);
            expect(guest.reports.get(0)).toBe(report1);
            expect(guest.reports.get(1)).toBe(report2); 
        });
    });

    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.size).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.size).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.size).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.size).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.size).toBe(1);

            const report2 = makeActiveFill(0, date, good_event, active_fill_emotion);
            await guest.createCBTReportActiveFill(date, good_event, active_fill_emotion);
            expect(guest.reports.size).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.size).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.size).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.size).toBe(1);
            await guest.createCBTReportActiveFill(date,good_event,[],"hand",thought,response);
            expect(guest.reports.size).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 = new CBTReportContext(date,fill,0);
            const guest = new Guest();
            await guest.addReport(report);
            expect(guest.reports.size).toBe(1);
            expect(guest.reports.get(0)).toBe(report);
            guest.removeReportbyIndex(0);
            expect(guest.reports.size).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 = new CBTReportContext(date,fill,0);
            const guest = new Guest();
            await guest.addReport(report)
            expect(guest.reports.size).toBe(1);
            expect(guest.reports.get(0)).toBe(report);
            expect(()=>guest.removeReportbyIndex(1)).toThrow(Guest.outofReportssBoundsError);
            expect(guest.reports.size).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 = new CBTReportContext(date,fill,0);
            const guest = new Guest()
            await guest.addReport(report)
            expect(guest.reports.size).toBe(1);
            expect(guest.reports.get(0)).toBe(report);
            expect(()=>guest.removeReportbyIndex(1)).toThrow(Guest.outofReportssBoundsError);
            expect(guest.reports.size).toBe(1);

        });


        test('checking add report with and remove with two items', async () =>{
            const report1 = new CBTReportContext(date1,fill1,0);
            const date2 = new Date(Date.now());
            const report2 = new CBTReportContext(date2,fill2,1);
            const guest = new Guest();
            await guest.addReport(report1);
            expect(guest.reports.size).toBe(1);
            await guest.addReport(report2);
            expect(guest.reports.size).toBe(2);
            expect(guest.reports.get(0)).toBe(report1);
            expect(guest.reports.get(1)).toBe(report2);
            guest.removeReportbyIndex(0);
            expect(guest.reports.size).toBe(1);
            expect(guest.reports.get(1)).toBe(report2);

        });

        test('checking add report with and remove with two items one good second out of range', async () =>{
            const report1 = new CBTReportContext(date1,fill1,0);
            const date2 = new Date(Date.now()-100);
            const report2 = new CBTReportContext(date2,fill2,1);
            const guest = new Guest();
            await guest.addReport(report1);
            expect(guest.reports.size).toBe(1);
            await guest.addReport(report2);
            expect(guest.reports.size).toBe(2);
            expect(guest.reports.get(0)).toBe(report1);
            expect(guest.reports.get(1)).toBe(report2);
            guest.removeReportbyIndex(0)
            expect(()=>guest.removeReportbyIndex(0)).toThrow(Guest.outofReportssBoundsError);
            expect(guest.reports.size).toBe(1);
            expect(guest.reports.get(1)).toBe(report2);

        });

    });
    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 = new CBTReportContext(date,fill,0);
            const guest = new Guest()
            await guest.addReport(report)
            expect(guest.reports.size).toBe(1);
            expect(guest.getSummary()).toBe(report.getSummary());
        });

        test('checking get summary with two reports', async () =>{
            const report1 = new CBTReportContext(date1,fill1,0);
            const date2 = new Date(Date.now());
            const report2 = new CBTReportContext(date2,fill2,1);
            const guest = new Guest();
            await guest.addReport(report1);
            expect(guest.reports.size).toBe(1);
            await guest.addReport(report2);
            expect(guest.reports.size).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.size).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 = new CBTReportContext(date,fill,0);
                const guest = new Guest()
                await guest.addReport(report)
                expect(guest.reports.size).toBe(1);
                expect(guest.getSummary()).toBe(report.getSummary());
                let storedreport = await getValue({"UserName": "Guest","index": "0", "DataType":DType.CBTReportContext})
                if(storedreport!= undefined)
                {
                    expect(storedreport.constructor.name).toBe(CBTReportContext.name);
                    expect(storedreport.getSummary())
                 .toBe(report.getSummary());
                }
            });
    
            test('checking get summary Storage with two reports', async () =>{
                        const report1 = new CBTReportContext(date1,fill1,0);
                const date2 = new Date(Date.now()-100);
                    const report2 = new CBTReportContext(date2,fill2,1);
                const guest = new Guest();
                await guest.addReport(report1);
                expect(guest.reports.size).toBe(1);
                await guest.addReport(report2);
                expect(guest.reports.size).toBe(2);
                expect(guest.getSummary())
                .toBe(report1.getSummary()+"\n"+report2.getSummary());


                let storedreport1 = await getValue({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
                if(storedreport1!= undefined)
                {
                    expect(storedreport1.constructor.name).toBe(CBTReportContext.name);
                    expect(storedreport1.getSummary())
                 .toBe(report1.getSummary());
                }

                let storedreport2 = await getValue({"UserName": "Guest","index":"1", "DataType":DType.CBTReportContext})
                if(storedreport2!= undefined)
                {
                    expect(storedreport2.constructor.name).toBe(CBTReportContext.name);
                    expect(storedreport2.getSummary())
                 .toBe(report2.getSummary());
                }
            });
    
            
            test('checking delete Storage with ', async () =>{
                        const report1 = new CBTReportContext(date1,fill1,0);
                const date2 = new Date(Date.now()-100);
                    const report2 = new CBTReportContext(date2,fill2,1);
                const guest = new Guest();
                await guest.addReport(report1);
                expect(guest.reports.size).toBe(1);
                await guest.addReport(report2);
                expect(guest.reports.size).toBe(2);
                expect(guest.getSummary())
                .toBe(report1.getSummary()+"\n"+report2.getSummary());


                let storedreport1 = await getValue({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
                if(storedreport1!= undefined)
                {
                    expect(storedreport1.constructor.name).toBe(CBTReportContext.name);
                    expect(storedreport1.getSummary())
                 .toBe(report1.getSummary());
                }

                let storedreport2 = await getValue({"UserName": "Guest","index":"1", "DataType":DType.CBTReportContext})
                if(storedreport2!= undefined)
                {date2
                    expect(storedreport2.constructor.name).toBe(CBTReportContext.name);
                    expect(storedreport2.getSummary())
                 .toBe(report2.getSummary());
                }

                guest.removeReportbyIndex(1);
                await expect(async ()=>  getValue({"UserName": "Guest","index":"1", "DataType":DType.CBTReportContext})).rejects.toThrow("Problem in Storage");


                let storedreportmore1 = await getValue({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
                if(storedreportmore1!= undefined)
                {
                    expect(storedreportmore1.constructor.name).toBe(CBTReportContext.name);
                    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.size).toBe(1);
                let storedreport = await getValue({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
                if(storedreport!= undefined)
                {
                    expect(storedreport.constructor.name).toBe(CBTReportContext.name);
                    expect(guest.reports.get(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.size).toBe(1);
                await sleep(2000);
                const date2 = new Date(Date.now());
                await guest.createCBTReportActiveFill(date2,good_event,[],"hand",thought,response);
                expect(guest.reports.size).toBe(2);
                let storedreport = await getValue({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
                if(storedreport!= undefined)
                {
                    expect(storedreport.constructor.name).toBe(CBTReportContext.name);
                    expect(guest.reports.get(0)).toBeDefined();
                    expect(storedreport.getSummary()).toBe(guest.reports.get(0)?.getSummary());
                }
                let storedreport2 = await getValue({"UserName": "Guest","index":"1", "DataType":DType.CBTReportContext})
                if(storedreport2!= undefined)
                {
                    expect(storedreport2.constructor.name).toBe(CBTReportContext.name);
                    expect(guest.reports.get(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 () =>{
    
                const guest = new Guest()
                await guest.createCBTReportActiveFill(date1,good_event,[],valid_body_part);
                expect(guest.reports.size).toBe(1);
                let storedreport = await getValue({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
                if(storedreport!= undefined)
                {
                    expect(storedreport.constructor.name).toBe(CBTReportContext.name);
                    expect(guest.reports.get(0)).toBeDefined();
                    expect(storedreport.getSummary())
                 .toBe(guest.reports.get(0)?.getSummary());
                }
                guest.reports = new Map<number, CBTReportContext>();
                expect(guest.reports.size).toBe(0);

            await guest.getAllCBTReportsFromStorage();
            expect(guest.reports.size).toBe(1);
            if(storedreport!= undefined)
            {
                expect(storedreport.constructor.name).toBe(CBTReportContext.name);
                expect(guest.reports.get(0)).toBeDefined();
                expect(storedreport.getSummary())
                .toBe(guest.reports.get(0)?.getSummary());
            }
        });



        test('checking get all Storage with two report', async () =>{
            const bp = "hand";

            const guest = new Guest()

            await guest.createCBTReportActiveFill(date1,good_event,[],bp);
            expect(guest.reports.size).toBe(1);
            const date2 = new Date(Date.now()-100);
            await guest.createCBTReportActiveFill(date2,good_event,[],"head",thought,response);
            expect(guest.reports.size).toBe(2);

                let storedreport = await getValue({"UserName": "Guest","index":"0", "DataType":DType.CBTReportContext})
                if(storedreport!= undefined)
                {
                    expect(storedreport.constructor.name).toBe(CBTReportContext.name);
                    expect(guest.reports.get(0)).toBeDefined();
                    expect(storedreport.getSummary())
                        .toBe(guest.reports.get(0)?.getSummary());
                }

                
                let storedreport2 = await getValue({"UserName": "Guest","index":"1", "DataType":DType.CBTReportContext})
                if(storedreport2!= undefined)
                {
                    expect(storedreport2.constructor.name).toBe(CBTReportContext.name);
                    expect(guest.reports.get(1)).toBeDefined();
                    expect(storedreport2.getSummary())
                        .toBe(guest.reports.get(1)?.getSummary());
                }



            guest.reports = new Map<number, CBTReportContext>();
            expect(guest.reports.size).toBe(0);

            await guest.getAllCBTReportsFromStorage();
            expect(guest.reports.size).toBe(2);
            if(storedreport!= undefined)
            {
                expect(storedreport.constructor.name).toBe(CBTReportContext.name);
                expect(guest.reports.get(0)).toBeDefined();
                expect(storedreport.getSummary())
                    .toBe(guest.reports.get(0)?.getSummary());
            }

            if(storedreport2!= undefined)
            {
                expect(storedreport2.constructor.name).toBe(CBTReportContext.name);
                expect(guest.reports.get(1)).toBeDefined();
                expect(storedreport2.getSummary())
                    .toBe(guest.reports.get(1)?.getSummary());
            }
        });
    });


    describe("Guest getReports tests", () => {
        beforeEach(async () => await wipe_guest());
        test('checking getReports 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 = new CBTReportContext(date,fill,0);
            const guest = new Guest()
            await guest.addReport(report)
            expect(guest.reports.size).toBe(1);
            expect(guest.reports.get(0)).toBe(report);
            expect(guest.getReports(formatdate)[0]).toBe(report);
        });

        test('checking getReports with two report', async () =>{
            const formatdate = new Date("2023/01");
            const report1 = new CBTReportContext(date1,fill1,0);
            const date2 = new Date(Date.now()-86400000);
            const report2 = new CBTReportContext(date2,fill2,1);
            const guest = new Guest();
            await guest.addReport(report1);
            expect(guest.reports.size).toBe(1);
            await guest.addReport(report2);
            expect(guest.reports.size).toBe(2);
            expect(guest.getReports(formatdate)[0]).toBe(report1);
            expect(guest.getReports(formatdate)[1]).toBe(report2);
        });


        test('checking getReports with two report and not one', async () =>{
            const formatdate = new Date("2023/01");
            const report1 = new CBTReportContext(date1,fill1,0);
            const date2 = new Date(Date.now()-86400000);
            const report2 = new CBTReportContext(date2,fill2,1);

            const date3 = new Date(Date.now()-(86400000*1000));
            const report3 = new CBTReportContext(date3,fill3,1);
            const guest = new Guest();
            await guest.addReport(report1);
            await guest.addReport(report2);
            await guest.addReport(report3);

            expect(guest.reports.size).toBe(3);
            expect(guest.getReports(formatdate)[0]).toBe(report1);
            expect(guest.getReports(formatdate)[1]).toBe(report2);
            expect(guest.getReports(formatdate).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 = new CBTReportContext(date,fill,0);
            const guest = new Guest();
            await guest.addReport(report);
            expect(guest.reports.size).toBe(1);
            expect(guest.reports.get(0)).toBe(report);
            expect(guest.getReportofSpecificDate(date)).toBe(report);
        });

        test('checking getReportbyspecificdate with two report one good', async () =>{
            const formatdate = new Date("2023/01");
            const report1 = new CBTReportContext(date1,fill1,0);
            const date2 = new Date(Date.now()-86400000);
            const report2 = new CBTReportContext(date2,fill2,1);
            const guest = new Guest();
            await guest.addReport(report1);
            expect(guest.reports.size).toBe(1);
            await guest.addReport(report2);
            expect(guest.reports.size).toBe(2);
            expect(guest.getReportofSpecificDate(date1)).toBe(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 = new CBTReportContext(date,fill,0);
            const guest = new Guest()
            await guest.addReport(report)
            expect(guest.reports.size).toBe(1);
            expect(guest.reports.get(0)).toBe(report);

        });

        test('checking add report with two report', async () =>{
            const date = new Date(Date.now());
            const report1 = new CBTReportContext(date,fill1,0);
            const report2 = new CBTReportContext(date,fill2,1);
            const guest = new Guest();
            await guest.addReport(report1);
            expect(guest.reports.size).toBe(1);
            await guest.addReport(report2);
            expect(guest.reports.size).toBe(2);
            expect(guest.reports.get(0)).toBe(report1);
            expect(guest.reports.get(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.size).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(Date.now());
            

            const guest = new Guest();

            const date2 = new Date(Date.now()-86400000);
            const report2 = new CBTReportContext(date2,fill2,2);

            const date3 = new Date(Date.now()-(86400000*2));
            const fill3 = new ActiveFill("feeling good", [],new BodyPartSelection(bodyParts["hand"]));
            const report3 = new CBTReportContext(date3,fill3,3);

            report2.creationDate = date2;
            report3.creationDate = 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(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 report2 = new CBTReportContext(date2,fill2,2);

            const date3 = new Date(Date.now()-(86400000));
            const fill3 = new ActiveFill("feeling good", [],new BodyPartSelection(bodyParts["hand"]));
            const report3 = new CBTReportContext(date3,fill3,3);
            report2.creationDate = date2;
            report3.creationDate = 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.size).toBe(1);
            const achievements = guest.getAchievements();
            expect(await getValueofAchievements("Guest")).toStrictEqual(guest.achievements);

        });

        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 report2 = new CBTReportContext(date2,fill2,2);

            const date3 = new Date(Date.now()-(86400000*2));
            const fill3 = new ActiveFill("feeling good",[], new BodyPartSelection(bodyParts["hand"]));
            const report3 = new CBTReportContext(date3,fill3,3);

            report2.creationDate = date2;
            report3.creationDate = date3;

            await guest.addReport(report3);
            expect(await getValueofAchievements("Guest")).toStrictEqual(guest.achievements);

            await guest.addReport(report2);
            expect(await getValueofAchievements("Guest")).toStrictEqual(guest.achievements);

            await guest.createCBTReportActiveFill(date,feeling_good_event,active_fill_emotion,thought,response);

            const achievements = guest.getAchievements();
            expect(await getValueofAchievements("Guest")).toStrictEqual(guest.achievements);

            expect( (await getValueofAchievements("Guest")).rewardFillReportInaRow).toStrictEqual(3);
            expect( (await getValueofAchievements("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 report2 = new CBTReportContext(date2,fill2,2);

            const date3 = new Date(Date.now()-(86400000));
            const fill3 = new ActiveFill("feeling good",[], new BodyPartSelection(bodyParts["hand"]));
            const report3 = new CBTReportContext(date3,fill3,3);

            report2.creationDate = date2;
            report3.creationDate = date3;

            await guest.addReport(report3);
            expect(await getValueofAchievements("Guest")).toStrictEqual(guest.achievements);

            await guest.addReport(report2);
            expect(await getValueofAchievements("Guest")).toStrictEqual(guest.achievements);

            await guest.createCBTReportActiveFill(date,feeling_good_event,active_fill_emotion,thought,response);

            const achievements = guest.getAchievements();
            expect(await getValueofAchievements("Guest")).toStrictEqual(guest.achievements);

            expect( (await getValueofAchievements("Guest")).rewardFillReportInaRow).toStrictEqual(2);
            expect( (await getValueofAchievements("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 = new CBTReportContext(date2,fill2,2);

            const date3 = new Date(Date.now()-(86400000));
            const fill3 = new ActiveFill("feeling good", [],new BodyPartSelection(bodyParts["hand"]));
            const report3 = new CBTReportContext(date3,fill3,3);

            report2.creationDate = date2;
            report3.creationDate = date3;

            await guest.addReport(report3);
            expect(await getValueofAchievements("Guest")).toStrictEqual(guest.achievements);

            await guest.addReport(report2);
            expect(await getValueofAchievements("Guest")).toStrictEqual(guest.achievements);

            await guest.createCBTReportActiveFill(date,feeling_good_event,active_fill_emotion,thought,response);

            const achievements = guest.getAchievements();
            expect(await getValueofAchievements("Guest")).toStrictEqual(guest.achievements);

            expect( (await getValueofAchievements("Guest")).rewardFillReportInaRow).toStrictEqual(2);
            expect( (await getValueofAchievements("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 CBTReportContext(date1,fill,0, guest.getDraft()?.creationDate);
            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 bad_fill = new ActiveFill(feeling_good_event, active_fill_emotion,valid_body_part_selection, thought, response);
            const creationDate = guest.draft?.creationDate;
            guest.draft = new CBTReportContext(valid_date, bad_fill, guest.reports.size);
            const fill = new ActiveFill(good_event, active_fill_emotion,valid_body_part_selection, thought, response);
            const report = new CBTReportContext(date1,fill,undefined, creationDate);
            await guest.getDraftFromStorageTest();
            expect(guest.getDraft()).toStrictEqual(report);
        });
    });