From 05765495c493701d2d307b58ca37da415db11675 Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Wed, 9 Oct 2024 11:53:33 -0400 Subject: [PATCH] test(NotificationsService): add snapshot test to legacy script execution error --- .../notifications.service.spec.ts.snap | 21 +++++++++++++++++++ .../notifications.service.spec.ts | 8 +++++++ 2 files changed, 29 insertions(+) diff --git a/api/src/unraid-api/graph/resolvers/notifications/__snapshots__/notifications.service.spec.ts.snap b/api/src/unraid-api/graph/resolvers/notifications/__snapshots__/notifications.service.spec.ts.snap index b33032047..a0c04c154 100644 --- a/api/src/unraid-api/graph/resolvers/notifications/__snapshots__/notifications.service.spec.ts.snap +++ b/api/src/unraid-api/graph/resolvers/notifications/__snapshots__/notifications.service.spec.ts.snap @@ -6,14 +6,35 @@ exports[`NotificationsService legacy script compatibility > yields correct cli a ©®™✓✓✓—“”‘’" -l "https://unraid.net/?query=param&special=💡🔥✨"" `; +exports[`NotificationsService legacy script compatibility > yields correct cli args for alerts 2`] = ` +"Command failed with ENOENT: /usr/local/emhttp/webGui/scripts/notify -i alert -e Test Notification !@#$%^&*()_+={}[]|:;"'<>,.?/~\` -s Test Subject +🚀💻🛠️ -d Test Description with special characters +©®™✓✓✓—“”‘’ -l https://unraid.net/?query=param&special=💡🔥✨ +spawn /usr/local/emhttp/webGui/scripts/notify ENOENT" +`; + exports[`NotificationsService legacy script compatibility > yields correct cli args for normals 1`] = ` ""/usr/local/emhttp/webGui/scripts/notify" -i normal -e "Test Notification !@#$%^&*()_+={}[]|:;\\"'<>,.?/~\`" -s "Test Subject 🚀💻🛠️" -d "Test Description with special characters ©®™✓✓✓—“”‘’" -l "https://unraid.net/?query=param&special=💡🔥✨"" `; +exports[`NotificationsService legacy script compatibility > yields correct cli args for normals 2`] = ` +"Command failed with ENOENT: /usr/local/emhttp/webGui/scripts/notify -i normal -e Test Notification !@#$%^&*()_+={}[]|:;"'<>,.?/~\` -s Test Subject +🚀💻🛠️ -d Test Description with special characters +©®™✓✓✓—“”‘’ -l https://unraid.net/?query=param&special=💡🔥✨ +spawn /usr/local/emhttp/webGui/scripts/notify ENOENT" +`; + exports[`NotificationsService legacy script compatibility > yields correct cli args for warnings 1`] = ` ""/usr/local/emhttp/webGui/scripts/notify" -i warning -e "Test Notification !@#$%^&*()_+={}[]|:;\\"'<>,.?/~\`" -s "Test Subject 🚀💻🛠️" -d "Test Description with special characters ©®™✓✓✓—“”‘’" -l "https://unraid.net/?query=param&special=💡🔥✨"" `; + +exports[`NotificationsService legacy script compatibility > yields correct cli args for warnings 2`] = ` +"Command failed with ENOENT: /usr/local/emhttp/webGui/scripts/notify -i warning -e Test Notification !@#$%^&*()_+={}[]|:;"'<>,.?/~\` -s Test Subject +🚀💻🛠️ -d Test Description with special characters +©®™✓✓✓—“”‘’ -l https://unraid.net/?query=param&special=💡🔥✨ +spawn /usr/local/emhttp/webGui/scripts/notify ENOENT" +`; diff --git a/api/src/unraid-api/graph/resolvers/notifications/notifications.service.spec.ts b/api/src/unraid-api/graph/resolvers/notifications/notifications.service.spec.ts index e05518f87..c1cfcba54 100644 --- a/api/src/unraid-api/graph/resolvers/notifications/notifications.service.spec.ts +++ b/api/src/unraid-api/graph/resolvers/notifications/notifications.service.spec.ts @@ -407,6 +407,14 @@ describe.concurrent('NotificationsService legacy script compatibility', () => { const result = await execa(cmd, args, { reject: false }); expect.soft(result.escapedCommand).toMatchSnapshot(); + + if (result.failed) { + // @ts-expect-error this is correct; `execa`'s return type just isn't comprehensive + // see https://github.com/sindresorhus/execa/blob/main/docs/errors.md#error-message + // + //* we use a snapshot because the script should only fail when it doesn't exist (ENOENT) + expect(result.message).toMatchSnapshot(); + } } ); });