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>,
|
||||
) => Promise<boolean>;
|
||||
logout: () => Promise<void>;
|
||||
mailboxClose: () => Promise<void>;
|
||||
}
|
||||
|
||||
type Email = {
|
||||
@ -287,7 +288,10 @@ export const perform = (
|
||||
if (O.isSome(e.imap)) {
|
||||
const imap = e.imap.value;
|
||||
return pipe(
|
||||
TE.tryCatch(() => imap.logout(), toError),
|
||||
TE.tryCatch(
|
||||
() => imap.mailboxClose().then(() => imap.logout()),
|
||||
toError,
|
||||
),
|
||||
TE.flatMap(() => TE.left(e)),
|
||||
);
|
||||
}
|
||||
@ -295,8 +299,13 @@ export const perform = (
|
||||
},
|
||||
({ mailboxLock, deleted, imap }) => {
|
||||
mailboxLock.release();
|
||||
imap.logout();
|
||||
return TE.right(deleted);
|
||||
return pipe(
|
||||
TE.tryCatch(
|
||||
() => imap.mailboxClose().then(() => imap.logout()),
|
||||
toError,
|
||||
),
|
||||
TE.flatMap(() => TE.right(deleted)),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
@ -32,6 +32,7 @@ const getMocks = () => {
|
||||
getMailboxLock: mock(() => Promise.resolve(lock)),
|
||||
messageDelete: mock(() => Promise.resolve(true)),
|
||||
logout: mock(() => Promise.resolve()),
|
||||
mailboxClose: mock(() => Promise.resolve()),
|
||||
};
|
||||
|
||||
const mockDependencies: Partial<EmailJobDependencies> = {
|
||||
@ -116,6 +117,7 @@ test("releases lock on left", async () => {
|
||||
TE.mapLeft(() => {
|
||||
expect(imap.getMailboxLock).toHaveBeenCalledTimes(1);
|
||||
expect(lock.release).toHaveBeenCalledTimes(1);
|
||||
expect(imap.mailboxClose).toHaveBeenCalledTimes(1);
|
||||
expect(imap.logout).toHaveBeenCalledTimes(1);
|
||||
}),
|
||||
)();
|
||||
@ -133,6 +135,7 @@ test("releases lock on right", async () => {
|
||||
expect(imap.getMailboxLock).toHaveBeenCalledTimes(1);
|
||||
expect(lock.release).toHaveBeenCalledTimes(1);
|
||||
expect(imap.logout).toHaveBeenCalledTimes(1);
|
||||
expect(imap.mailboxClose).toHaveBeenCalledTimes(1);
|
||||
}),
|
||||
TE.mapLeft(() => expect(false).toBeTruthy()),
|
||||
)();
|
||||
|
Loading…
Reference in New Issue
Block a user