From b19782fbc53d5e2e85aa68c4ad43f9789ba3027b Mon Sep 17 00:00:00 2001
From: Stuart Clark <stu@rtclark.net>
Date: Tue, 13 Aug 2024 12:51:03 +1000
Subject: [PATCH] chore(#693): update druxt-schema tests

---
 packages/schema/test/nuxt/index.test.js | 53 +++++++++++++++++++++++++
 packages/schema/test/nuxtModule.test.js | 45 ---------------------
 2 files changed, 53 insertions(+), 45 deletions(-)
 create mode 100644 packages/schema/test/nuxt/index.test.js
 delete mode 100644 packages/schema/test/nuxtModule.test.js

diff --git a/packages/schema/test/nuxt/index.test.js b/packages/schema/test/nuxt/index.test.js
new file mode 100644
index 000000000..8f0040959
--- /dev/null
+++ b/packages/schema/test/nuxt/index.test.js
@@ -0,0 +1,53 @@
+import { DruxtSchema } from '../../src'
+import DruxtSchemaNuxtModule from '../../src/nuxt'
+
+jest.mock('@nuxt/kit', () => ({
+  addTemplate: jest.fn(),
+  addPluginTemplate: jest.fn(),
+  defineNuxtModule: (module) => module,
+  installModule: jest.fn(),
+  useLogger: jest.fn(() => ({
+    success: jest.fn(),
+  })),
+}))
+
+import { addPluginTemplate, addTemplate } from '@nuxt/kit'
+
+jest.mock('../../src/schema')
+let nuxtMock
+
+describe('Nuxt module', () => {
+  beforeEach(() => {
+    jest.clearAllMocks()
+    nuxtMock = {
+      hook: async (hook, fn) => await fn(),
+      options: {
+        druxt: {
+          baseUrl: 'https://demo-api.druxtjs.org',
+        },
+      },
+    }
+  })
+
+  test('Default', async () => {
+    DruxtSchema.mockImplementation(() => ({
+      get: () => ({
+        schemas: {
+          'node--page--default--view': {},
+          'node--article--default--view': undefined
+        }
+      })
+    }))
+    await DruxtSchemaNuxtModule.setup({}, nuxtMock)
+    expect(addPluginTemplate).toHaveBeenCalled()
+    expect(addTemplate).toHaveBeenCalledTimes(1)
+  })
+
+  test('No schemas', async () => {
+    DruxtSchema.mockImplementation(() => ({
+      get: () => ({ schemas: {} })
+    }))
+    await DruxtSchemaNuxtModule.setup({}, nuxtMock)
+    expect(addTemplate).toHaveBeenCalledTimes(0)
+  })
+})
diff --git a/packages/schema/test/nuxtModule.test.js b/packages/schema/test/nuxtModule.test.js
deleted file mode 100644
index 2df09f2c5..000000000
--- a/packages/schema/test/nuxtModule.test.js
+++ /dev/null
@@ -1,45 +0,0 @@
-import DruxtSchemaNuxtModule, { DruxtSchema } from '../src'
-
-jest.mock('../src/schema')
-let mock
-
-describe('Nuxt module', () => {
-  beforeEach(() => {
-    mock = {
-      addPlugin: jest.fn(),
-      addTemplate: jest.fn(),
-      nuxt: {
-        hook: async (hook, fn) => await fn()
-      },
-      options: {
-        druxt: {
-          baseUrl: 'https://demo-api.druxtjs.org',
-        },
-      },
-      DruxtSchemaNuxtModule
-    }
-
-  })
-
-  test('Default', async () => {
-    DruxtSchema.mockImplementation(() => ({
-      get: () => ({
-        schemas: {
-          'node--page--default--view': {},
-          'node--article--default--view': undefined
-        }
-      })
-    }))
-    await DruxtSchemaNuxtModule.call(mock)
-    expect(mock.addPlugin).toHaveBeenCalled()
-    expect(mock.addTemplate).toHaveBeenCalledTimes(1)
-  })
-
-  test('No schemas', async () => {
-    DruxtSchema.mockImplementation(() => ({
-      get: () => ({ schemas: {} })
-    }))
-    await DruxtSchemaNuxtModule.call(mock)
-    expect(mock.addTemplate).toHaveBeenCalledTimes(0)
-  })
-})