Repository: hyperjumptech/monika
Pull request #966 (2022-12-30 03:56:55)

Fixed: Fix GitHub checks warnings
# Monika Pull Request (PR)  

## What feature/issue does this PR add  
As a part of the effort to solve issue #679.

## How did you implement / how did you fix it  
Fix the violated codes of the following rules
 
  - [max-params](https://eslint.org/docs/latest/rules/max-params)
  - [no-use-before-define](https://eslint.org/docs/latest/rules/no-use-before-define)
  - [unicorn/prefer-module](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-module.md)

## How to test  
1. Run `npm run posttest`
2. Run Monika as usual

codecov[bot]: # [Codecov](https://codecov.io/gh/hyperjumptech/monika/pull/966?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hyperjumptech) Report
> Merging [#966](https://codecov.io/gh/hyperjumptech/monika/pull/966?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hyperjumptech) (959acf5) into [main](https://codecov.io/gh/hyperjumptech/monika/commit/ec62f1601082581305467b2c1f9a25221ba5cf2a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hyperjumptech) (ec62f16) will **decrease** coverage by `0.03%`.
> The diff coverage is `33.33%`.

```diff
@@            Coverage Diff             @@
##             main     #966      +/-   ##
==========================================
- Coverage   45.32%   45.28%   -0.04%     
==========================================
  Files          86       86              
  Lines        2921     2919       -2     
  Branches      583      583              
==========================================
- Hits         1324     1322       -2     
  Misses       1391     1391              
  Partials      206      206              
```


| [Impacted Files](https://codecov.io/gh/hyperjumptech/monika/pull/966?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hyperjumptech) | Coverage Δ | |
|---|---|---|
| [src/components/config/index.ts](https://codecov.io/gh/hyperjumptech/monika/pull/966/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hyperjumptech#diff-c3JjL2NvbXBvbmVudHMvY29uZmlnL2luZGV4LnRz) | `62.58% <33.33%> (-0.51%)` | :arrow_down: |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hyperjumptech)


Patch:
diff --git a/custom_types/nodemailer-mock/index.d.ts b/custom_types/nodemailer-mock/index.d.ts
new file mode 100644
index 00000000..eb50bfba
--- /dev/null
+++ b/custom_types/nodemailer-mock/index.d.ts
@@ -0,0 +1,25 @@
+/**********************************************************************************
+ * MIT License                                                                    *
+ *                                                                                *
+ * Copyright (c) 2021 Hyperjump Technology                                        *
+ *                                                                                *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy   *
+ * of this software and associated documentation files (the "Software"), to deal  *
+ * in the Software without restriction, including without limitation the rights   *
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell      *
+ * copies of the Software, and to permit persons to whom the Software is          *
+ * furnished to do so, subject to the following conditions:                       *
+ *                                                                                *
+ * The above copyright notice and this permission notice shall be included in all *
+ * copies or substantial portions of the Software.                                *
+ *                                                                                *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR     *
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,       *
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE    *
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER         *
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  *
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  *
+ * SOFTWARE.                                                                      *
+ **********************************************************************************/
+
+declare module 'nodemailer-mock'
diff --git a/src/components/config/index.ts b/src/components/config/index.ts
index 4bc880be..a2a446ec 100644
--- a/src/components/config/index.ts
+++ b/src/components/config/index.ts
@@ -42,6 +42,20 @@ import { createConfigFile } from './create-config'
 import yml from 'js-yaml'
 import { exit } from 'process'
 
+type ScheduleRemoteConfigFetcherParams = {
+  configType: 'monika' | 'har' | 'insomnia' | 'postman' | 'sitemap' | 'text'
+  interval: number
+  url: string
+  index?: number
+}
+
+type WatchConfigFileParams = {
+  path: string
+  type: string
+  index?: number
+  repeat?: number
+}
+
 const emitter = getEventEmitter()
 
 let cfg: Config
@@ -109,22 +123,16 @@ const mergeConfigs = (): Config => {
   return mergedConfig as Config
 }
 
-const watchConfigFile = (
-  path: string,
-  type: string,
-  index?: number,
-  repeat?: number,
-  flags?: MonikaFlags
-) => {
-  const watchConfigFile = !(
+function watchConfigFile({ path, type, index, repeat }: WatchConfigFileParams) {
+  const isWatchConfigFile = !(
     process.env.CI ||
     process.env.NODE_ENV === 'test' ||
     repeat !== 0
   )
-  if (watchConfigFile) {
+  if (isWatchConfigFile) {
     const watcher = chokidar.watch(path)
     watcher.on('change', async () => {
-      const newConfig = await parseConfig(path, type, flags)
+      const newConfig = await parseConfig(path, type)
       if (index === undefined) {
         nonDefaultConfig = newConfig
       } else {
@@ -136,16 +144,15 @@ const watchConfigFile = (
   }
 }
 
-const scheduleRemoteConfigFetcher = (
-  url: string,
-  configType: 'monika' | 'har' | 'insomnia' | 'postman' | 'sitemap' | 'text',
-  interval: number,
-  index?: number,
-  flags?: MonikaFlags
-) => {
+function scheduleRemoteConfigFetcher({
+  configType,
+  interval,
+  url,
+  index,
+}: ScheduleRemoteConfigFetcherParams) {
   setInterval(async () => {
     try {
-      const newConfig = await parseConfig(url, configType, flags)
+      const newConfig = await parseConfig(url, configType)
       if (index === undefined) {
         nonDefaultConfig = newConfig
       } else {
@@ -168,9 +175,14 @@ const parseConfigType = async (
   if (isUrl(source)) {
     const interval: number =
       flags['config-interval'] || monikaFlagsDefaultValue['config-interval']
-    scheduleRemoteConfigFetcher(source, configType, interval, index)
+    scheduleRemoteConfigFetcher({ configType, interval, url: source, index })
   } else {
-    watchConfigFile(source, configType, index, flags.repeat)
+    watchConfigFile({
+      path: source,
+      type: configType,
+      index,
+      repeat: flags.repeat,
+    })
   }
 
   const parsed = await parseConfig(source, configType, flags)
diff --git a/src/interfaces/notification.ts b/src/interfaces/notification.ts
index 7c36cd1f..241866ca 100644
--- a/src/interfaces/notification.ts
+++ b/src/interfaces/notification.ts
@@ -44,28 +44,6 @@ import {
   PushbulletData,
 } from './data'
 
-export type Notification =
-  | SMTPNotification
-  | MailgunNotification
-  | SendgridNotification
-  | WebhookNotification
-  | SlackNotification
-  | WhatsappBusinessNotification
-  | MonikaWhatsappNotification
-  | TeamsNotification
-  | TelegramNotification
-  | DiscordNotification
-  | WorkplaceNotification
-  | DesktopNotification
-  | LarkNotification
-  | DingtalkNotification
-  | GoogleChatNotification
-  | PagerDutyNotification
-  | PushoverNotification
-  | GotifyNotification
-  | OpsgenieNotification
-  | StatuspageNotification
-  | PushbulletNotification
 interface BaseNotification {
   id: string
 }
@@ -167,15 +145,28 @@ interface PushbulletNotification extends BaseNotification {
   data: PushbulletData
 }
 
-export interface NotificationMessage {
-  subject: string
-  body: string
-  summary: string
-  meta:
-    | NotificationIncidentRecoveryMessageMeta
-    | NotificationStartTerminationMessageMeta
-    | NotificationStatusUpdateMessageMeta
-}
+export type Notification =
+  | SMTPNotification
+  | MailgunNotification
+  | SendgridNotification
+  | WebhookNotification
+  | SlackNotification
+  | WhatsappBusinessNotification
+  | MonikaWhatsappNotification
+  | TeamsNotification
+  | TelegramNotification
+  | DiscordNotification
+  | WorkplaceNotification
+  | DesktopNotification
+  | LarkNotification
+  | DingtalkNotification
+  | GoogleChatNotification
+  | PagerDutyNotification
+  | PushoverNotification
+  | GotifyNotification
+  | OpsgenieNotification
+  | StatuspageNotification
+  | PushbulletNotification
 
 interface BaseNotificationMessageMeta {
   type: string
@@ -207,3 +198,13 @@ interface NotificationStatusUpdateMessageMeta
   numberOfRecoveries: number
   numberOfSentNotifications: number
 }
+
+export interface NotificationMessage {
+  subject: string
+  body: string
+  summary: string
+  meta:
+    | NotificationIncidentRecoveryMessageMeta
+    | NotificationStartTerminationMessageMeta
+    | NotificationStatusUpdateMessageMeta
+}


Test patch:
diff --git a/test/others/smtp.test.ts b/test/others/smtp.test.ts
index 3bec9209..28ee5053 100644
--- a/test/others/smtp.test.ts
+++ b/test/others/smtp.test.ts
@@ -23,6 +23,7 @@
  **********************************************************************************/
 
 import { expect } from '@oclif/test'
+import mailMock from 'nodemailer-mock'
 import {
   createSmtpTransport,
   sendSmtpMail,
@@ -30,8 +31,6 @@ import {
 import Mail from 'nodemailer/lib/mailer'
 import { SMTPData } from '../../src/interfaces/data'
 
-const mailMock = require('nodemailer-mock')
-
 const transport: Mail = mailMock.createTransport({
   host: '127.0.0.1',
   port: 2323,