This commit is contained in:
parent
8e5fabec3e
commit
6f45fe5a10
15
src/email.ts
15
src/email.ts
@ -26,6 +26,7 @@ interface ImapClientI {
|
|||||||
opts: Record<string, any>,
|
opts: Record<string, any>,
|
||||||
) => Promise<boolean>;
|
) => Promise<boolean>;
|
||||||
logout: () => Promise<void>;
|
logout: () => Promise<void>;
|
||||||
|
mailboxClose: () => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
type Email = {
|
type Email = {
|
||||||
@ -287,7 +288,10 @@ export const perform = (
|
|||||||
if (O.isSome(e.imap)) {
|
if (O.isSome(e.imap)) {
|
||||||
const imap = e.imap.value;
|
const imap = e.imap.value;
|
||||||
return pipe(
|
return pipe(
|
||||||
TE.tryCatch(() => imap.logout(), toError),
|
TE.tryCatch(
|
||||||
|
() => imap.mailboxClose().then(() => imap.logout()),
|
||||||
|
toError,
|
||||||
|
),
|
||||||
TE.flatMap(() => TE.left(e)),
|
TE.flatMap(() => TE.left(e)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -295,8 +299,13 @@ export const perform = (
|
|||||||
},
|
},
|
||||||
({ mailboxLock, deleted, imap }) => {
|
({ mailboxLock, deleted, imap }) => {
|
||||||
mailboxLock.release();
|
mailboxLock.release();
|
||||||
imap.logout();
|
return pipe(
|
||||||
return TE.right(deleted);
|
TE.tryCatch(
|
||||||
|
() => imap.mailboxClose().then(() => imap.logout()),
|
||||||
|
toError,
|
||||||
|
),
|
||||||
|
TE.flatMap(() => TE.right(deleted)),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -32,6 +32,7 @@ const getMocks = () => {
|
|||||||
getMailboxLock: mock(() => Promise.resolve(lock)),
|
getMailboxLock: mock(() => Promise.resolve(lock)),
|
||||||
messageDelete: mock(() => Promise.resolve(true)),
|
messageDelete: mock(() => Promise.resolve(true)),
|
||||||
logout: mock(() => Promise.resolve()),
|
logout: mock(() => Promise.resolve()),
|
||||||
|
mailboxClose: mock(() => Promise.resolve()),
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockDependencies: Partial<EmailJobDependencies> = {
|
const mockDependencies: Partial<EmailJobDependencies> = {
|
||||||
@ -116,6 +117,7 @@ test("releases lock on left", async () => {
|
|||||||
TE.mapLeft(() => {
|
TE.mapLeft(() => {
|
||||||
expect(imap.getMailboxLock).toHaveBeenCalledTimes(1);
|
expect(imap.getMailboxLock).toHaveBeenCalledTimes(1);
|
||||||
expect(lock.release).toHaveBeenCalledTimes(1);
|
expect(lock.release).toHaveBeenCalledTimes(1);
|
||||||
|
expect(imap.mailboxClose).toHaveBeenCalledTimes(1);
|
||||||
expect(imap.logout).toHaveBeenCalledTimes(1);
|
expect(imap.logout).toHaveBeenCalledTimes(1);
|
||||||
}),
|
}),
|
||||||
)();
|
)();
|
||||||
@ -133,6 +135,7 @@ test("releases lock on right", async () => {
|
|||||||
expect(imap.getMailboxLock).toHaveBeenCalledTimes(1);
|
expect(imap.getMailboxLock).toHaveBeenCalledTimes(1);
|
||||||
expect(lock.release).toHaveBeenCalledTimes(1);
|
expect(lock.release).toHaveBeenCalledTimes(1);
|
||||||
expect(imap.logout).toHaveBeenCalledTimes(1);
|
expect(imap.logout).toHaveBeenCalledTimes(1);
|
||||||
|
expect(imap.mailboxClose).toHaveBeenCalledTimes(1);
|
||||||
}),
|
}),
|
||||||
TE.mapLeft(() => expect(false).toBeTruthy()),
|
TE.mapLeft(() => expect(false).toBeTruthy()),
|
||||||
)();
|
)();
|
||||||
|
Loading…
Reference in New Issue
Block a user