From 456ea9996ef765759e9744fcb28d51dd10c94de7 Mon Sep 17 00:00:00 2001 From: f-w Date: Wed, 4 Dec 2024 15:53:49 -0800 Subject: [PATCH] replace deprecated jest methods --- test/cron.e2e-spec.ts | 8 +-- test/inbound-smtp-server.e2e-spec.ts | 42 +++++++------- test/notification.e2e-spec.ts | 86 +++++++++++++++------------- test/subscription.e2e-spec.ts | 58 +++++++++---------- 4 files changed, 100 insertions(+), 94 deletions(-) diff --git a/test/cron.e2e-spec.ts b/test/cron.e2e-spec.ts index 96f224ea6..4500f1c00 100644 --- a/test/cron.e2e-spec.ts +++ b/test/cron.e2e-spec.ts @@ -455,7 +455,7 @@ describe('CRON checkRssConfigUpdates', function () { fail(err); } await wait(1000); - expect(fetch as unknown as jest.SpyInstance).toBeCalledWith( + expect(fetch as unknown as jest.SpyInstance).toHaveBeenCalledWith( 'http://foo/api/notifications', expect.objectContaining({ method: 'POST', @@ -495,7 +495,7 @@ describe('CRON checkRssConfigUpdates', function () { await rssService.create(data); await cronTasksService.checkRssConfigUpdates(true); await wait(2000); - expect(fetch as unknown as jest.SpyInstance).not.toBeCalledWith( + expect(fetch as unknown as jest.SpyInstance).not.toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ method: 'POST' }), ); @@ -546,7 +546,7 @@ describe('CRON checkRssConfigUpdates', function () { .mockReturnValueOnce(null); await cronTasksService.checkRssConfigUpdates(true); await wait(1000); - expect(loggerErrorSpy).toBeCalledWith( + expect(loggerErrorSpy).toHaveBeenCalledWith( expect.objectContaining({ message: 'Bad status code', }), @@ -658,7 +658,7 @@ describe('CRON reDispatchBroadcastPushNotifications', () => { await wait(3000); const mockedSendEmail = CommonService.prototype .sendEmail as unknown as jest.SpyInstance; - expect(mockedSendEmail).toBeCalledWith( + expect(mockedSendEmail).toHaveBeenCalledWith( expect.objectContaining({ from: 'admin@foo.com', to: 'bar@foo.com', diff --git a/test/inbound-smtp-server.e2e-spec.ts b/test/inbound-smtp-server.e2e-spec.ts index cf32fda0d..34ee261df 100644 --- a/test/inbound-smtp-server.e2e-spec.ts +++ b/test/inbound-smtp-server.e2e-spec.ts @@ -98,7 +98,7 @@ describe('list-unsubscribe by email', function () { expect(info.accepted.length).toEqual(1); expect(smtpSvr.onRcptTo).toHaveBeenCalled(); expect(smtpSvr.onData).toHaveBeenCalled(); - expect(fetch as unknown as jest.SpyInstance).toBeCalledWith( + expect(fetch as unknown as jest.SpyInstance).toHaveBeenCalledWith( `http://localhost:3000/api/subscriptions/${subId}/unsubscribe?unsubscriptionCode=12345&userChannelId=bar%40foo.com`, { headers: { @@ -123,8 +123,8 @@ describe('list-unsubscribe by email', function () { } catch (err) { expect(err.rejected.length).toEqual(1); } - expect(smtpSvr.onRcptTo).toBeCalled; - expect(smtpSvr.onData).not.toBeCalled(); + expect(smtpSvr.onRcptTo).toHaveBeenCalled; + expect(smtpSvr.onData).not.toHaveBeenCalled(); connection.quit(); }); @@ -141,8 +141,8 @@ describe('list-unsubscribe by email', function () { } catch (err) { expect(err.rejected.length).toEqual(1); } - expect(smtpSvr.onRcptTo).toBeCalled(); - expect(smtpSvr.onData).not.toBeCalled(); + expect(smtpSvr.onRcptTo).toHaveBeenCalled(); + expect(smtpSvr.onData).not.toHaveBeenCalled(); connection.quit(); }); }); @@ -219,8 +219,8 @@ describe('bounce', function () { `Received: from localhost (localhost)\r\n\tby foo.invalid.local (8.14.4/8.14.4) id w7TItYs4100793;\r\n\tWed, 29 Aug 2018 11:55:34 -0700\r\nDate: Wed, 29 Aug 2018 11:55:34 -0700\r\nFrom: Mail Delivery Subsystem \r\nMessage-Id: <201808291855.w7TItYs4100793@foo.invalid.local>\r\nTo: \r\nMIME-Version: 1.0\r\nContent-Type: multipart/report; report-type=delivery-status;\r\n\tboundary="w7TItYs4100793.1535568934/foo.invalid.local"\r\nSubject: Returned mail: see transcript for details\r\nAuto-Submitted: auto-generated (failure)\r\n\r\nThis is a MIME-encapsulated message\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local\r\n\r\nThe original message was received at Wed, 29 Aug 2018 11:55:34 -0700\r\nfrom invalid.local [0.0.0.0]\r\n\r\n ----- The following addresses had permanent fatal errors -----\r\n\r\n (reason: 550-5.1.1 The email account that you tried to reach does not exist. Please try)\r\n\r\n ----- Transcript of session follows -----\r\n... while talking to gmail-smtp-in.l.google.com.:\r\n>>> DATA\r\n<<< 550-5.1.1 The email account that you tried to reach does not exist. Please try\r\n<<< 550-5.1.1 double-checking the recipient's email address for typos or\r\n<<< 550-5.1.1 unnecessary spaces. Learn more at\r\n<<< 550 5.1.1 https://support.google.com/mail/?p=NoSuchUser c17-v6si4448431pge.273 - gsmtp\r\n550 5.1.1 ... User unknown\r\n<<< 503 5.5.1 RCPT first. c17-v6si4448431pge.273 - gsmtp\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local\r\nContent-Type: message/delivery-status\r\n\r\nReporting-MTA: dns; foo.invalid.local\r\nReceived-From-MTA: DNS; invalid.local\r\nArrival-Date: Wed, 29 Aug 2018 11:55:34 -0700\r\n\r\nFinal-Recipient: RFC822; bar@foo.com\r\nAction: failed\r\nStatus: 5.1.1\r\nRemote-MTA: DNS; gmail-smtp-in.l.google.com\r\nDiagnostic-Code: SMTP; 550-5.1.1 The email account that you tried to reach does not exist. Please try\r\nLast-Attempt-Date: Wed, 29 Aug 2018 11:55:34 -0700\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local\r\nContent-Type: message/rfc822\r\n\r\nReturn-Path: \r\nReceived: from [127.0.0.1] (invalid.local [0.0.0.0])\r\n\tby foo.invalid.local (8.14.4/8.14.4) with ESMTP id w7TIqOs6099075\r\n\t(version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO)\r\n\tfor ; Wed, 29 Aug 2018 11:55:34 -0700\r\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n d=mail.www2.invalid.local; q=dns/txt; s=dev;\r\n bh=wrkCugmpWjuk1K/MNn64VeMFmvd+ef1KHXTHHL+GO84=;\r\n h=from:subject:date:message-id:to:mime-version:content-type:list-id:list-unsubscribe;\r\n b=O5i568MBJIL38+umlZxJGAG+vffxe89cbUNbCrjt/QDHRiiLBcLpZBMPTqvQnEJX6gwLXnBkj\r\n m/69oke2/HmSTp9T/I0MmwenuqpEc7lhCeMfCvS19PTaQKb5tb/EK+TQt516yre3ElkCXrr/lyg\r\n PPrZozr8rupPNhK5NZNpABJXQtCQEfdF8Fw7OnHWalvch7Q5jfta84EQ6zOGAC6HfLFe0O/VkVf\r\n sbEwGGyC9OOEyGBpppEMBGx8qXuZxSpxiaWGdGVhW6jf/WLghPwThvDgRYSq9jTNfenMXR2LAPf\r\n FbjSR6GqrRowS4h2GVVyPTYk1SGT0uGJucNa/vlDWgnQ==\r\nContent-Type: multipart/alternative;\r\n boundary="--_NmP-6ea6170c81eda5cc-Part_1"\r\nFrom: donotreply@invalid.local\r\nTo: bar@foo.com\r\nSubject: test\r\nMessage-ID: <1d6819a2-698c-eea7-f3e8-fa4977801d49@invalid.local>\r\nList-ID: \r\nList-Unsubscribe: , \r\nDate: Wed, 29 Aug 2018 18:55:34 +0000\r\nMIME-Version: 1.0\r\nX-Scanned-By: MIMEDefang 2.70 on 0.0.0.0\r\n\r\n----_NmP-6ea6170c81eda5cc-Part_1\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nThis is a test https://invalid.local/notifybc/api/subscriptions/5b50c=\r\nb6e953d170b24983019/unsubscribe?unsubscriptionCode=3D42074\r\n----_NmP-6ea6170c81eda5cc-Part_1\r\nContent-Type: text/html\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nThis is a test.\r\n----_NmP-6ea6170c81eda5cc-Part_1--\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local--\r\n\r\n`, ); expect(info.accepted.length).toEqual(1); - expect(smtpSvr.onRcptTo).toBeCalled(); - expect(smtpSvr.onData).toBeCalled(); + expect(smtpSvr.onRcptTo).toHaveBeenCalled(); + expect(smtpSvr.onData).toHaveBeenCalled(); connection.quit(); }); }); @@ -277,8 +277,8 @@ describe('bounce', function () { `Received: from localhost (localhost)\r\n\tby foo.invalid.local (8.14.4/8.14.4) id w7TItYs4100793;\r\n\tWed, 29 Aug 2018 11:55:34 -0700\r\nDate: Wed, 29 Aug 2018 11:55:34 -0700\r\nFrom: Mail Delivery Subsystem \r\nMessage-Id: <201808291855.w7TItYs4100793@foo.invalid.local>\r\nTo: \r\nMIME-Version: 1.0\r\nContent-Type: multipart/report; report-type=delivery-status;\r\n\tboundary="w7TItYs4100793.1535568934/foo.invalid.local"\r\nSubject: Returned mail: see transcript for details\r\nAuto-Submitted: auto-generated (failure)\r\n\r\nThis is a MIME-encapsulated message\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local\r\nContent-Type: message/delivery-status\r\n\r\nReporting-MTA: dns; foo.invalid.local\r\nReceived-From-MTA: DNS; invalid.local\r\nArrival-Date: Wed, 29 Aug 2018 11:55:34 -0700\r\n\r\nFinal-Recipient: RFC822; bar@foo.com\r\nAction: failed\r\nStatus: 5.1.1\r\nRemote-MTA: DNS; gmail-smtp-in.l.google.com\r\nDiagnostic-Code: SMTP; 550-5.1.1 The email account that you tried to reach does not exist. Please try\r\nLast-Attempt-Date: Wed, 29 Aug 2018 11:55:34 -0700\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local--\r\n\r\n`, ); expect(info.accepted.length).toEqual(1); - expect(smtpSvr.onRcptTo).toBeCalled(); - expect(smtpSvr.onData).toBeCalled(); + expect(smtpSvr.onRcptTo).toHaveBeenCalled(); + expect(smtpSvr.onData).toHaveBeenCalled(); connection.quit(); const rec = await bouncesService.findById(bounceId); expect(rec.hardBounceCount).toEqual(2); @@ -337,8 +337,8 @@ describe('bounce', function () { `From: Mail Delivery Subsystem \r\nMessage-Id: <201808291855.w7TItYs4100793@foo.invalid.local>\r\nTo: \r\nMIME-Version: 1.0\r\nContent-Type: multipart/report; report-type=delivery-status;\r\n\tboundary="w7TItYs4100793.1535568934/foo.invalid.local"\r\nSubject: invalid\r\n\r\nThis is a MIME-encapsulated message\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local\r\nContent-Type: message/delivery-status\r\n\r\nReporting-MTA: dns; foo.invalid.local\r\nReceived-From-MTA: DNS; invalid.local\r\nArrival-Date: Wed, 29 Aug 2018 11:55:34 -0700\r\n\r\nFinal-Recipient: RFC822; bar@foo.com\r\nAction: failed\r\nStatus: 5.1.1\r\nRemote-MTA: DNS; gmail-smtp-in.l.google.com\r\nDiagnostic-Code: SMTP; 550-5.1.1 The email account that you tried to reach does not exist. Please try\r\nLast-Attempt-Date: Wed, 29 Aug 2018 11:55:34 -0700\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local--\r\n\r\n`, ); expect(info.accepted.length).toEqual(1); - expect(smtpSvr.onRcptTo).toBeCalled(); - expect(smtpSvr.onData).toBeCalled(); + expect(smtpSvr.onRcptTo).toHaveBeenCalled(); + expect(smtpSvr.onData).toHaveBeenCalled(); connection.quit(); const rec = await bouncesService.findById(bounceId); expect(rec.hardBounceCount).toEqual(1); @@ -397,8 +397,8 @@ describe('bounce', function () { `From: Mail Delivery Subsystem \r\nTo: \r\nMIME-Version: 1.0\r\nContent-Type: multipart/report; report-type=delivery-status;\r\n\tboundary="w7TItYs4100793.1535568934/foo.invalid.local"\r\nSubject: Returned mail: see transcript for details\r\nAuto-Submitted: auto-generated (failure)\r\n\r\nThis is a MIME-encapsulated message\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local\r\nContent-Type: message/delivery-status\r\n\r\nReporting-MTA: dns; foo.invalid.local\r\nReceived-From-MTA: DNS; invalid.local\r\nArrival-Date: Wed, 29 Aug 2018 11:55:34 -0700\r\n\r\nFinal-Recipient: RFC822; bar@foo.com\r\nAction: failed\r\nStatus: 4.1.1\r\n\r\n`, ); expect(info.accepted.length).toEqual(1); - expect(smtpSvr.onRcptTo).toBeCalled(); - expect(smtpSvr.onData).toBeCalled(); + expect(smtpSvr.onRcptTo).toHaveBeenCalled(); + expect(smtpSvr.onData).toHaveBeenCalled(); connection.quit(); const rec = await bouncesService.findById(bounceId); expect(rec.hardBounceCount).toEqual(1); @@ -457,8 +457,8 @@ describe('bounce', function () { `From: Mail Delivery Subsystem \r\nTo: \r\nMIME-Version: 1.0\r\nContent-Type: multipart/report; report-type=delivery-status;\r\n\tboundary="w7TItYs4100793.1535568934/foo.invalid.local"\r\nSubject: Returned mail: see transcript for details\r\nAuto-Submitted: auto-generated (failure)\r\n\r\nThis is a MIME-encapsulated message\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local\r\nContent-Type: message/delivery-status\r\n\r\nReporting-MTA: dns; foo.invalid.local\r\nReceived-From-MTA: DNS; invalid.local\r\nArrival-Date: Wed, 29 Aug 2018 11:55:34 -0700\r\n\r\nFinal-Recipient: RFC822; bar@invalid.local\r\nAction: failed\r\nStatus: 5.1.1\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local\r\n\r\n`, ); expect(info.accepted.length).toEqual(1); - expect(smtpSvr.onRcptTo).toBeCalled(); - expect(smtpSvr.onData).toBeCalled(); + expect(smtpSvr.onRcptTo).toHaveBeenCalled(); + expect(smtpSvr.onData).toHaveBeenCalled(); connection.quit(); const rec = await bouncesService.findById(bounceId); expect(rec.hardBounceCount).toEqual(1); @@ -517,8 +517,8 @@ describe('bounce', function () { `From: Mail Delivery Subsystem \r\nTo: \r\nMIME-Version: 1.0\r\nContent-Type: multipart/report; report-type=delivery-status;\r\n\tboundary="w7TItYs4100793.1535568934/foo.invalid.local"\r\nSubject: Returned mail: see transcript for details\r\nX-Failed-Recipients: bar@foo.com\r\nAuto-Submitted: auto-generated (failure)\r\n\r\nThis is a MIME-encapsulated message\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local\r\nContent-Type: message/delivery-status\r\n\r\nReporting-MTA: dns; foo.invalid.local\r\nReceived-From-MTA: DNS; invalid.local\r\nArrival-Date: Wed, 29 Aug 2018 11:55:34 -0700\r\n\r\nFinal-Recipient: RFC822; bar@invalid.local\r\nAction: failed\r\nStatus: 5.1.1\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local\r\n\r\n`, ); expect(info.accepted.length).toEqual(1); - expect(smtpSvr.onRcptTo).toBeCalled(); - expect(smtpSvr.onData).toBeCalled(); + expect(smtpSvr.onRcptTo).toHaveBeenCalled(); + expect(smtpSvr.onData).toHaveBeenCalled(); connection.quit(); const rec = await bouncesService.findById(bounceId); expect(rec.hardBounceCount).toEqual(2); @@ -583,8 +583,8 @@ describe('bounce', function () { `Received: from localhost (localhost)\r\n\tby foo.invalid.local (8.14.4/8.14.4) id w7TItYs4100793;\r\n\tWed, 29 Aug 2018 11:55:34 -0700\r\nDate: Wed, 29 Aug 2018 11:55:34 -0700\r\nFrom: Mail Delivery Subsystem \r\nMessage-Id: <201808291855.w7TItYs4100793@foo.invalid.local>\r\nTo: \r\nMIME-Version: 1.0\r\nContent-Type: multipart/report; report-type=delivery-status;\r\n\tboundary="w7TItYs4100793.1535568934/foo.invalid.local"\r\nSubject: Returned mail: see transcript for details\r\nAuto-Submitted: auto-generated (failure)\r\n\r\nThis is a MIME-encapsulated message\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local\r\n\r\nThe original message was received at Wed, 29 Aug 2018 11:55:34 -0700\r\nfrom invalid.local [0.0.0.0]\r\n\r\n ----- The following addresses had permanent fatal errors -----\r\n\r\n (reason: 550-5.1.1 The email account that you tried to reach does not exist. Please try)\r\n\r\n ----- Transcript of session follows -----\r\n... while talking to gmail-smtp-in.l.google.com.:\r\n>>> DATA\r\n<<< 550-5.1.1 The email account that you tried to reach does not exist. Please try\r\n<<< 550-5.1.1 double-checking the recipient's email address for typos or\r\n<<< 550-5.1.1 unnecessary spaces. Learn more at\r\n<<< 550 5.1.1 https://support.google.com/mail/?p=NoSuchUser c17-v6si4448431pge.273 - gsmtp\r\n550 5.1.1 ... User unknown\r\n<<< 503 5.5.1 RCPT first. c17-v6si4448431pge.273 - gsmtp\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local\r\nContent-Type: message/delivery-status\r\n\r\nReporting-MTA: dns; foo.invalid.local\r\nReceived-From-MTA: DNS; invalid.local\r\nArrival-Date: Wed, 29 Aug 2018 11:55:34 -0700\r\n\r\nFinal-Recipient: RFC822; bar@foo.com\r\nAction: failed\r\nStatus: 5.1.1\r\nRemote-MTA: DNS; gmail-smtp-in.l.google.com\r\nDiagnostic-Code: SMTP; 550-5.1.1 The email account that you tried to reach does not exist. Please try\r\nLast-Attempt-Date: Wed, 29 Aug 2018 11:55:34 -0700\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local\r\nContent-Type: message/rfc822\r\n\r\nReturn-Path: \r\nReceived: from [127.0.0.1] (invalid.local [0.0.0.0])\r\n\tby foo.invalid.local (8.14.4/8.14.4) with ESMTP id w7TIqOs6099075\r\n\t(version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO)\r\n\tfor ; Wed, 29 Aug 2018 11:55:34 -0700\r\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n d=mail.www2.invalid.local; q=dns/txt; s=dev;\r\n bh=wrkCugmpWjuk1K/MNn64VeMFmvd+ef1KHXTHHL+GO84=;\r\n h=from:subject:date:message-id:to:mime-version:content-type:list-id:list-unsubscribe;\r\n b=O5i568MBJIL38+umlZxJGAG+vffxe89cbUNbCrjt/QDHRiiLBcLpZBMPTqvQnEJX6gwLXnBkj\r\n m/69oke2/HmSTp9T/I0MmwenuqpEc7lhCeMfCvS19PTaQKb5tb/EK+TQt516yre3ElkCXrr/lyg\r\n PPrZozr8rupPNhK5NZNpABJXQtCQEfdF8Fw7OnHWalvch7Q5jfta84EQ6zOGAC6HfLFe0O/VkVf\r\n sbEwGGyC9OOEyGBpppEMBGx8qXuZxSpxiaWGdGVhW6jf/WLghPwThvDgRYSq9jTNfenMXR2LAPf\r\n FbjSR6GqrRowS4h2GVVyPTYk1SGT0uGJucNa/vlDWgnQ==\r\nContent-Type: multipart/alternative;\r\n boundary="--_NmP-6ea6170c81eda5cc-Part_1"\r\nFrom: donotreply@invalid.local\r\nTo: bar@foo.com\r\nSubject: test\r\nMessage-ID: <1d6819a2-698c-eea7-f3e8-fa4977801d49@invalid.local>\r\nList-ID: \r\nList-Unsubscribe: , \r\nDate: Wed, 29 Aug 2018 18:55:34 +0000\r\nMIME-Version: 1.0\r\nX-Scanned-By: MIMEDefang 2.70 on 0.0.0.0\r\n\r\n----_NmP-6ea6170c81eda5cc-Part_1\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nThis is a test https://invalid.local/notifybc/api/subscriptions/5b50c=\r\nb6e953d170b24983019/unsubscribe?unsubscriptionCode=3D42074\r\n----_NmP-6ea6170c81eda5cc-Part_1\r\nContent-Type: text/html\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nThis is a test.\r\n----_NmP-6ea6170c81eda5cc-Part_1--\r\n\r\n--w7TItYs4100793.1535568934/foo.invalid.local--\r\n\r\n`, ); expect(info.accepted.length).toEqual(1); - expect(smtpSvr.onRcptTo).toBeCalled(); - expect(smtpSvr.onData).toBeCalled(); + expect(smtpSvr.onRcptTo).toHaveBeenCalled(); + expect(smtpSvr.onData).toHaveBeenCalled(); connection.quit(); const rec = await bouncesService.findById(bounceId); expect(rec.state).toEqual('deleted'); @@ -608,8 +608,8 @@ describe('bounce', function () { } catch (err) { expect(err.responseCode).toEqual(451); } - expect(smtpSvr.onRcptTo).toBeCalled(); - expect(smtpSvr.onData).toBeCalled(); + expect(smtpSvr.onRcptTo).toHaveBeenCalled(); + expect(smtpSvr.onData).toHaveBeenCalled(); connection.quit(); }); }); diff --git a/test/notification.e2e-spec.ts b/test/notification.e2e-spec.ts index 564196445..16332a355 100644 --- a/test/notification.e2e-spec.ts +++ b/test/notification.e2e-spec.ts @@ -230,159 +230,159 @@ describe('POST /notifications', () => { expect(res.status).toEqual(200); const spiedSendEmail = CommonService.prototype .sendEmail as unknown as jest.SpyInstance; - expect(spiedSendEmail).toBeCalled(); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenCalled(); + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ text: expect.not.stringContaining('{confirmation_code}'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ text: expect.not.stringContaining('{service_name}'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ text: expect.not.stringContaining('{http_host}'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ text: expect.not.stringContaining('{rest_api_root}'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ text: expect.not.stringContaining('{subscription_id}'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ text: expect.not.stringContaining('{unsubscription_code}'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ text: expect.stringContaining('12345'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ text: expect.stringContaining('myService'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ text: expect.stringContaining('http://127.0.0.1'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ text: expect.stringContaining('/api'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ text: expect.stringContaining('54321'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ text: expect.stringContaining('bar foo male'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ text: expect.stringContaining('{1} {2}, This is a broadcast test'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ html: expect.not.stringContaining('{confirmation_code}'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ html: expect.not.stringContaining('{service_name}'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ html: expect.not.stringContaining('{http_host}'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ html: expect.not.stringContaining('{rest_api_root}'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ html: expect.not.stringContaining('{subscription_id}'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ html: expect.not.stringContaining('{unsubscription_code}'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ html: expect.stringContaining('12345'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ html: expect.stringContaining('myService'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ html: expect.stringContaining('http://127.0.0.1'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ html: expect.stringContaining('/api'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ html: expect.stringContaining('54321'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ html: expect.stringContaining('bar foo male'), }), ); - expect(spiedSendEmail).nthCalledWith( + expect(spiedSendEmail).toHaveBeenNthCalledWith( 1, expect.objectContaining({ html: expect.stringContaining('{1} {2}, This is a broadcast test'), @@ -429,7 +429,7 @@ describe('POST /notifications', () => { expect(res.status).toEqual(200); expect( CommonService.prototype.sendEmail as unknown as jest.SpyInstance, - ).toBeCalled(); + ).toHaveBeenCalled(); const data = await notificationsService.findAll( { where: { @@ -461,7 +461,7 @@ describe('POST /notifications', () => { expect(res.status).toEqual(200); expect( CommonService.prototype.sendSMS as unknown as jest.SpyInstance, - ).toBeCalled(); + ).toHaveBeenCalled(); const data = await notificationsService.findAll( { where: { @@ -492,7 +492,7 @@ describe('POST /notifications', () => { expect(res.status).toEqual(200); expect( CommonService.prototype.sendSMS as unknown as jest.SpyInstance, - ).toBeCalled(); + ).toHaveBeenCalled(); const data = await notificationsService.findAll( { where: { @@ -529,7 +529,7 @@ describe('POST /notifications', () => { }) .set('Accept', 'application/json'); expect(res.status).toEqual(200); - expect(mockedFetch).toBeCalledTimes(1); + expect(mockedFetch).toHaveBeenCalledTimes(1); const data = await notificationsService.findAll( { where: { @@ -564,7 +564,7 @@ describe('POST /notifications', () => { expect(res.status).toEqual(200); expect( CommonService.prototype.sendEmail as unknown as jest.SpyInstance, - ).not.toBeCalled(); + ).not.toHaveBeenCalled(); const data = await notificationsService.findAll( { where: { @@ -727,7 +727,10 @@ describe('POST /notifications', () => { ); expect(data.length).toEqual(1); expect(data[0].state).toEqual('sent'); - expect(spiedFetch).toBeCalledWith('http://foo.com', expect.any(Object)); + expect(spiedFetch).toHaveBeenCalledWith( + 'http://foo.com', + expect.any(Object), + ); }); }, ); @@ -838,11 +841,14 @@ describe('POST /notifications', () => { ); expect(data.length).toEqual(1); expect(data[0].state).toEqual('sent'); - expect(spiedFetch).toBeCalledWith('http://foo.com', expect.any(Object)); + expect(spiedFetch).toHaveBeenCalledWith( + 'http://foo.com', + expect.any(Object), + ); expect( CommonService.prototype.sendEmail as unknown as jest.SpyInstance, - ).toBeCalledTimes(2); + ).toHaveBeenCalledTimes(2); expect( data[0].dispatch.candidates.indexOf(promiseAllRes[3].id), ).toBeGreaterThanOrEqual(0); @@ -884,7 +890,7 @@ describe('POST /notifications', () => { expect(res.status).toEqual(200); expect( CommonService.prototype.sendEmail as unknown as jest.SpyInstance, - ).not.toBeCalled(); + ).not.toHaveBeenCalled(); const data = await notificationsService.findAll( { where: { @@ -967,7 +973,7 @@ describe('POST /notifications', () => { expect(res.status).toEqual(200); expect( CommonService.prototype.sendEmail as unknown as jest.SpyInstance, - ).toBeCalledTimes(1); + ).toHaveBeenCalledTimes(1); const data = await notificationsService.findAll( { where: { @@ -1009,7 +1015,7 @@ describe('POST /notifications', () => { expect(res.status).toEqual(200); expect( CommonService.prototype.sendEmail as unknown as jest.SpyInstance, - ).not.toBeCalled(); + ).not.toHaveBeenCalled(); const data = await notificationsService.findAll( { where: { @@ -1322,7 +1328,7 @@ describe('POST /notifications', () => { expect(res.status).toEqual(200); expect( CommonService.prototype.sendEmail as unknown as jest.SpyInstance, - ).toBeCalledTimes(1); + ).toHaveBeenCalledTimes(1); const data = await notificationsService.findAll( { where: { @@ -1389,7 +1395,7 @@ describe('POST /notifications', () => { expect(res.status).toEqual(200); expect( CommonService.prototype.sendEmail as unknown as jest.SpyInstance, - ).toBeCalledTimes(1); + ).toHaveBeenCalledTimes(1); const data = await notificationsService.findAll( { where: { diff --git a/test/subscription.e2e-spec.ts b/test/subscription.e2e-spec.ts index 21468d6b0..3a72e150f 100644 --- a/test/subscription.e2e-spec.ts +++ b/test/subscription.e2e-spec.ts @@ -105,7 +105,7 @@ describe('POST /subscriptions', function () { expect(res.status).toEqual(200); expect( CommonService.prototype.sendEmail as unknown as jest.SpyInstance, - ).not.toBeCalled(); + ).not.toHaveBeenCalled(); const data = await subscriptionsService.findAll( { where: { @@ -141,100 +141,100 @@ describe('POST /subscriptions', function () { expect(res.status).toEqual(200); const spiedSendEmail = CommonService.prototype .sendEmail as unknown as jest.SpyInstance; - expect(spiedSendEmail).toBeCalled(); - expect(spiedSendEmail).not.toBeCalledWith( + expect(spiedSendEmail).toHaveBeenCalled(); + expect(spiedSendEmail).not.toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('{subscription_confirmation_code}'), }), expect.anything(), ); - expect(spiedSendEmail).not.toBeCalledWith( + expect(spiedSendEmail).not.toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('{service_name}'), }), expect.anything(), ); - expect(spiedSendEmail).not.toBeCalledWith( + expect(spiedSendEmail).not.toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('{http_host}'), }), expect.anything(), ); - expect(spiedSendEmail).not.toBeCalledWith( + expect(spiedSendEmail).not.toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('{rest_api_root}'), }), expect.anything(), ); - expect(spiedSendEmail).not.toBeCalledWith( + expect(spiedSendEmail).not.toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('{subscription_id}'), }), expect.anything(), ); - expect(spiedSendEmail).not.toBeCalledWith( + expect(spiedSendEmail).not.toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('{unsubscription_code}'), }), expect.anything(), ); - expect(spiedSendEmail).not.toBeCalledWith( + expect(spiedSendEmail).not.toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('{unsubscription_url}'), }), expect.anything(), ); - expect(spiedSendEmail).not.toBeCalledWith( + expect(spiedSendEmail).not.toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('{subscription_confirmation_url}'), }), expect.anything(), ); - expect(spiedSendEmail).not.toBeCalledWith( + expect(spiedSendEmail).not.toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('{unsubscription_reversion_url}'), }), expect.anything(), ); - expect(spiedSendEmail).toBeCalledWith( + expect(spiedSendEmail).toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('12345'), }), 1, ); - expect(spiedSendEmail).toBeCalledWith( + expect(spiedSendEmail).toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('myService'), }), 1, ); - expect(spiedSendEmail).toBeCalledWith( + expect(spiedSendEmail).toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('http://127.0.0.1'), }), 1, ); - expect(spiedSendEmail).toBeCalledWith( + expect(spiedSendEmail).toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('/api'), }), 1, ); - expect(spiedSendEmail).toBeCalledWith( + expect(spiedSendEmail).toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('1 '), }), 1, ); - expect(spiedSendEmail).toBeCalledWith( + expect(spiedSendEmail).toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('54321'), }), 1, ); //unsubscription_url - expect(spiedSendEmail).toBeCalledWith( + expect(spiedSendEmail).toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining( `/api/subscriptions/${res.body.id}/unsubscribe?unsubscriptionCode=54321`, @@ -243,7 +243,7 @@ describe('POST /subscriptions', function () { 1, ); //subscription_confirmation_url - expect(spiedSendEmail).toBeCalledWith( + expect(spiedSendEmail).toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining( `/api/subscriptions/${res.body.id}/verify?confirmationCode=12345`, @@ -252,7 +252,7 @@ describe('POST /subscriptions', function () { 1, ); //unsubscription_reversion_url - expect(spiedSendEmail).toBeCalledWith( + expect(spiedSendEmail).toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining( `/api/subscriptions/${res.body.id}/unsubscribe/undo?unsubscriptionCode=54321`, @@ -287,7 +287,7 @@ describe('POST /subscriptions', function () { expect(res.status).toEqual(200); expect( CommonService.prototype.sendSMS as unknown as jest.SpyInstance, - ).toBeCalledTimes(1); + ).toHaveBeenCalledTimes(1); const data = await subscriptionsService.findAll( { where: { @@ -322,7 +322,7 @@ describe('POST /subscriptions', function () { expect(res.status).toEqual(200); expect( CommonService.prototype.sendEmail as unknown as jest.SpyInstance, - ).toBeCalledTimes(1); + ).toHaveBeenCalledTimes(1); const data = await subscriptionsService.findAll( { where: { @@ -353,8 +353,8 @@ describe('POST /subscriptions', function () { }) .set('Accept', 'application/json'); expect(res.status).toEqual(200); - expect(spiedSendSms).toBeCalledTimes(1); - expect(fetchStub).toBeCalledWith( + expect(spiedSendSms).toHaveBeenCalledTimes(1); + expect(fetchStub).toHaveBeenCalledWith( 'https://secure.smsgateway.ca/services/message.svc/123/12345', expect.anything(), ); @@ -393,7 +393,7 @@ describe('POST /subscriptions', function () { expect(res.status).toEqual(200); const spiedSendEmail = CommonService.prototype .sendEmail as unknown as jest.SpyInstance; - expect(spiedSendEmail).toBeCalledTimes(1); + expect(spiedSendEmail).toHaveBeenCalledTimes(1); const data = await subscriptionsService.findAll( { where: { @@ -443,7 +443,7 @@ describe('POST /subscriptions', function () { expect(res.status).toEqual(200); expect( CommonService.prototype.sendSMS as unknown as jest.SpyInstance, - ).toBeCalledTimes(1); + ).toHaveBeenCalledTimes(1); const data = await subscriptionsService.findAll( { where: { @@ -507,8 +507,8 @@ describe('POST /subscriptions', function () { expect(res.status).toEqual(200); const spiedSendEmail = CommonService.prototype .sendEmail as unknown as jest.SpyInstance; - expect(spiedSendEmail).toBeCalled(); - expect(spiedSendEmail).toBeCalledWith( + expect(spiedSendEmail).toHaveBeenCalled(); + expect(spiedSendEmail).toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringContaining('A duplicated subscription'), }), @@ -930,7 +930,7 @@ describe('GET /subscriptions/{id}/unsubscribe', () => { expect(res.length).toEqual(3); expect( CommonService.prototype.sendEmail as unknown as jest.SpyInstance, - ).toBeCalledWith( + ).toHaveBeenCalledWith( expect.objectContaining({ text: expect.stringMatching( /services myService\d, myService\d and myService\d/,