Unit Testing: Guest V3 - CBTYoung/Documentation GitHub Wiki

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);

1. Guest Add Reports Tests

    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 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);
        });
    });

1.1. Checking Add Report With One Report

When we add a report to an empty report pool, we expect the size to be 1.

1.2. Checking Add Report With Two Reports

When we add a report to a report pool, we expect the size to increase by 1. Here we check it twice.

1.3. Checking Add Report With Camera

When we add a report photo through camera context, we expect the size to increase by 1.

2. Paitent Create Reports Tests

    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);
        });
    });

2.1. Checking Create Report With Good Data

When we add a report with correct data, we expect it's data to be correct and the report pool size to increase by 1.

2.2. Checking Create Report With Bad Event Data

When we add a report with incorrect data, we expect the report pool size to stay the same.

2.3. Checking Create Report With Invalid Date

When we add a report with an invalid date, we expect the report pool size to stay the same.

2.4. Checking Create Report With Only Data

When we add a report with event only, we expect it's data to be correct and the report pool size to increase by 1.

2.5. Checking Create Report With Two Data

When we add a report with event only, we expect it's data to be correct and the report pool size to increase by 1. Here We check it twice.

2.6. Checking Create Report With Body Part

When we add a report with body parts, we expect it's data to be correct and the report pool size to increase by 1.

2.7. Checking Create Report With Wrong Date

When we add a correct partial report with wrong date and body part, we expect the report pool size to increase by 1.

2.8. Checking Create Report With Two Reports

When we add two reports with the same event name, we expect it's data to be correct and the report pool size to increase by 1 twice.

3. Guest Remove Report Tests

    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 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);
            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);
        });
    });

3.1. Checking Add Report And Removing It

We add a report and expect the report pool size to increase by 1. We then delete the report and expect the size to decrease by 1.

3.2. Checking Add Report And Remove With Wrong Index

We add a report and expect the report pool size to increase by 1. We then delete the wrong report and expect the size to stay the same.

3.3. Checking Add Report And Remove With Wrong Index

We add a report and expect the report pool size to increase by 1. We then delete the wrong report and expect the size to stay the same.

3.4. Checking Add Report And Remove With Two Items

We add two reports and expect the report pool size to increase by 1 twice. We then delete the two reports and expect the size to decrease by 1.

3.5. Checking Add Report And Remove With Two Items One Good Second Out Of Range

We add a report and expect the report pool size to increase by 1. We then delete the same report again and expect the size to stay the same.

3.6. Checking Add Report And Removing Camera Report

We add two Camera photo reports and expect the report pool size to increase by 1 twice. We then delete one report and expect the size to decrease by 1.

3.7. Checking Remove Report Of Camera

We add a Camera photo report and expect the report pool size to increase by 1. We then delete the report and expect the size to decrease by 1 and not throw an exeption.

4. Guest Summary Tests

    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());
        });

    });

4.1. Checking getSummary With One Report

We add a report and expect the report pool size to increase by 1. We then get it's summary and expect it to be identical.

4.2. Checking getSummary With Two Reports

We add two reports and expect the report pool size to increase by 1 twice. We then get one report's summary and expect it to be identical.

4.3. Checking getSummary With No Reports

We check there are no reports. We read one report's summary and expect it to be empty.

5. Guest Storage Tests

        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 getSummary', 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());
            }
        });
    });

5.1. Checking getSummary Storage With One Report

We add a report to Storage and expect the report size pool to increase by 1. We then get the summary from Storage and check it's identical.

5.2. Checking getSummary Storage With Two Reports

We add two reports to Storage and expect the report size pool to increase by 1 twice. We then get both summaries from Storage and check they are as expected.

5.3. Checking getSummary Storage With Remove

We add two reports to Storage and expect the report size pool to increase by 1 twice. We then get both summaries from Storage and check they are as expected. Afterwards, we remove one of the reports and check the report pool size decreased by 1.

5.4. Checking Create Report To Storage With One Report

We add a report to Storage and expect the report size pool to increase by 1. We then get the summary from Storage and check it's identical.

5.5. Checking Create Report To Storage With Two Reports

We add two reports to Storage and expect the report size pool to increase by 1 twice. We then get both summaries from Storage and check they are as expected.

5.6. Checking Get All From Storage With One Report

We add a report to Storage and expect the report size pool to increase by 1. We check the report we read from storage is the same as entered. We reload the user and check if the data in storage appears on the reloaded user.

5.7. Checking Get All From Storage With Two Reports

We add two reports to Storage and expect the report size pool to increase by 1 twice. We check the report we read from storage is the same as entered. We reload the user and check if the data in storage appears on the reloaded user.

5.8. Checking Create Camera Report To Storage With One Report

We add a Camera report to Storage and expect the report size pool to increase by 1. We then get the summary from Storage and check it's identical.

6. Guest getReports Tests

    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);
            
        });
       
    });

6.1. Checking getReports With One Report

We add a report and expect the report size pool to increase to 1. We then get all the reports from the last month and check if their size is 1.

6.2. Checking getReports With Two Reports

We add two reports and expect the report size pool to increase to 2. We then get all the reports from the last month and check if their size is 2.

6.3. Checking getReports With Two Reports And Not One

We add three reports, of which one is from the previous month. We then get all the reports from the last month and check if their size is 2.

7. Guest getReportbyspecificdate Tests

    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);
        });
       
    });

7.1. Checking getReportbyspecificdate With One Report

We add a report and expect the report size pool to increase by 1. We then get all reports by the current date and check if we get the report.

7.2. Checking getReportbyspecificdate With Two Reports One Good

We add two reports and expect the report size pool to increase by 1 twice. We then get all reports by the current date and check if we get only one correct report.

8. Guest Add Reports Tests

    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);

            
        });
       
    });

8.1. Checking Add Report With One Report

We add a report and expect the report size pool to increase by 1.

8.2. Checking Add Report With Two Reports

We add a report and expect the report size pool to increase by 1 twice.

9. Guest Check Achievements Tests

    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);
        });
    });

9.1. Checking Check Achievements With One Data

We add a report and expect the report size pool to increase by 1. We then check if the rewards for achievements changed accordingly.

9.2. Checking Check Achievements With Three Good Data

We add three reports consecutively and check if the rewards and streaks change accordingly.

9.3. Checking Check Achievements With Three Good Data Two In Same Day

We add three reports of which two of them are consecutively and one in the same day, and check if the rewards and streaks change accordingly.

10. Guest Check Achievements Storage Tests

    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);
        });
    });

10.1. Checking Check Achievements Storage With One Data

We add a report to Storage and expect the report size pool to increase by 1. We then check if the rewards for achievements changed accordingly.

10.2. Checking Check Achievements Storage With Three Good Data

We add three reports to Storage consecutively and check if the rewards and streaks change accordingly.

10.3. Checking Check Achievements Storage With Three Good Data Two In Same Day

We add three reports to Storage of which two of them are consecutively and one in the same day, and check if the rewards and streaks change accordingly.

10.4. Checking getachievementsfromStorage With Three Good Data Two In Same Day

We add three reports to Storage of which two of them are consecutively and one in the same day, and check if the rewards and streaks change accordingly. Afterwards, we reload the Achievements and check if the data was saved correctly.

11. Guest Draft Tests

    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);
        });
    });

11.1 Create Draft And Retrieve It

We create a draft of a report. We then retrieve it.

11.2 Create Draft And Retrieve It From Memory

We create a draft of a report. We then reload the draft and retrieve it.