"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const rxjs_1 = require("rxjs");
const types_1 = require("./types");
const deleteAppDataUseCase_1 = require("./deleteAppDataUseCase");
describe("deleteAppDataUseCase", () => {
    const deleteAppDataFn = jest.fn();
    afterEach(() => {
        jest.clearAllMocks();
    });
    describe("success cases", () => {
        it("should emit the correct events when the app data is deleted", done => {
            deleteAppDataFn.mockReturnValue((0, rxjs_1.from)([
                {
                    type: types_1.DeleteAppDataEventType.AppDataDeleteStarted,
                },
                {
                    type: types_1.DeleteAppDataEventType.AppDataDeleted,
                },
            ]));
            const deleteAppDataUseCaseObservable = (0, deleteAppDataUseCase_1.deleteAppDataUseCase)(deleteAppDataFn);
            const events = [];
            deleteAppDataUseCaseObservable.subscribe({
                next: (event) => events.push(event),
                complete: () => {
                    expect(events).toHaveLength(2);
                    expect(events[0]).toEqual({
                        type: types_1.DeleteAppDataEventType.AppDataDeleteStarted,
                    });
                    expect(events[1]).toEqual({
                        type: types_1.DeleteAppDataEventType.AppDataDeleted,
                    });
                    done();
                },
                error: (e) => {
                    done(e);
                },
            });
        });
        it("should emit the correct events when the app data is not found", done => {
            deleteAppDataFn.mockReturnValue((0, rxjs_1.from)([
                {
                    type: types_1.DeleteAppDataEventType.AppDataDeleteStarted,
                },
                {
                    type: types_1.DeleteAppDataEventType.NoAppDataToDelete,
                },
            ]));
            const events = [];
            (0, deleteAppDataUseCase_1.deleteAppDataUseCase)(deleteAppDataFn).subscribe({
                next: (event) => events.push(event),
                complete: () => {
                    expect(events).toHaveLength(2);
                    expect(events[0]).toEqual({
                        type: types_1.DeleteAppDataEventType.AppDataDeleteStarted,
                    });
                    expect(events[1]).toEqual({
                        type: types_1.DeleteAppDataEventType.NoAppDataToDelete,
                    });
                    done();
                },
                error: (e) => {
                    done(e);
                },
            });
        });
    });
    describe("error cases", () => {
        it("should emit the correct events when there is an error deleting the app data", done => {
            deleteAppDataFn.mockReturnValue((0, rxjs_1.concat)((0, rxjs_1.of)({
                type: types_1.DeleteAppDataEventType.AppDataDeleteStarted,
            }), (0, rxjs_1.throwError)(() => new types_1.DeleteAppDataError("Error deleting app data"))));
            const events = [];
            (0, deleteAppDataUseCase_1.deleteAppDataUseCase)(deleteAppDataFn).subscribe({
                next: (event) => events.push(event),
                complete: () => {
                    done(new Error("Should not complete"));
                },
                error: (e) => {
                    try {
                        expect(events).toHaveLength(1);
                        expect(events[0]).toEqual({
                            type: types_1.DeleteAppDataEventType.AppDataDeleteStarted,
                        });
                        expect(e).toEqual(new types_1.DeleteAppDataError("Error deleting app data"));
                        done();
                    }
                    catch (error) {
                        done(error);
                    }
                },
            });
        });
        it("should emit the correct events when there is an error getting the app data", done => {
            deleteAppDataFn.mockReturnValue((0, rxjs_1.concat)((0, rxjs_1.of)({
                type: types_1.DeleteAppDataEventType.AppDataDeleteStarted,
            }), (0, rxjs_1.throwError)(() => new types_1.DeleteAppDataError("Error getting app data"))));
            const events = [];
            (0, deleteAppDataUseCase_1.deleteAppDataUseCase)(deleteAppDataFn).subscribe({
                next: (event) => events.push(event),
                complete: () => {
                    done(new Error("Should not complete"));
                },
                error: (e) => {
                    try {
                        expect(events).toHaveLength(1);
                        expect(events[0]).toEqual({
                            type: types_1.DeleteAppDataEventType.AppDataDeleteStarted,
                        });
                        expect(e).toEqual(new types_1.DeleteAppDataError("Error getting app data"));
                        done();
                    }
                    catch (error) {
                        done(error);
                    }
                },
            });
        });
        it("should emit the correct events when there is an unknown error", done => {
            deleteAppDataFn.mockReturnValue((0, rxjs_1.concat)((0, rxjs_1.of)({
                type: types_1.DeleteAppDataEventType.AppDataDeleteStarted,
            }), (0, rxjs_1.throwError)(() => new Error("Unknown error"))));
            const events = [];
            (0, deleteAppDataUseCase_1.deleteAppDataUseCase)(deleteAppDataFn).subscribe({
                next: (event) => events.push(event),
                complete: () => {
                    done(new Error("Should not complete"));
                },
                error: (e) => {
                    try {
                        expect(events).toHaveLength(1);
                        expect(events[0]).toEqual({
                            type: types_1.DeleteAppDataEventType.AppDataDeleteStarted,
                        });
                        expect(e).toEqual(new Error("Unknown error"));
                        done();
                    }
                    catch (error) {
                        done(error);
                    }
                },
            });
        });
    });
});
//# sourceMappingURL=deleteAppDataUseCase.test.js.map