close the mailbox
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Elizabeth Hunt 2024-12-15 12:29:30 -08:00
parent 8e5fabec3e
commit 6f45fe5a10
Signed by: simponic
GPG Key ID: 2909B9A7FF6213EE
2 changed files with 15 additions and 3 deletions

View File

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

View File

@ -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()),
)(); )();