@pbvision/fastify-firestore-service 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/test/base-test.js +17 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pbvision/fastify-firestore-service",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "Web Framework using Fastify and Firestore ORM",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/test/base-test.js CHANGED
@@ -5,8 +5,14 @@ import { BaseTest, runTests } from '@pbvision/jest-unit-test'
5
5
  import superagentDefaults from 'superagent-defaults'
6
6
  import supertest from 'supertest'
7
7
 
8
+ import fetchWrapper from '../src/fetch-wrapper.js'
9
+
8
10
  let FASTIFY_CACHE
9
11
 
12
+ beforeAll(() => {
13
+ fetchWrapper.__mock = mockNodeFetch()
14
+ })
15
+
10
16
  afterAll(async () => {
11
17
  await FASTIFY_CACHE?.close()
12
18
  FASTIFY_CACHE = undefined
@@ -50,6 +56,10 @@ class BaseAppTest extends BaseTest {
50
56
  }
51
57
  })
52
58
  }
59
+
60
+ afterEach () {
61
+ fetchWrapper.__mock.mockReset()
62
+ }
53
63
  }
54
64
 
55
65
  function makeHeadersObj (headers) {
@@ -60,7 +70,7 @@ function makeHeadersObj (headers) {
60
70
 
61
71
  // the promise input conveniently matches the promise produced by supertest
62
72
  // so you can pass the output of app.post(), etc. as the promise here as is
63
- function makeGotMockValueFromPromise (promise) {
73
+ function makeNodeFetchMockValueFromPromise (promise) {
64
74
  const mockValue = new Promise(resolve => {
65
75
  promise.then(desiredHttpResponse => {
66
76
  let body = desiredHttpResponse.text || desiredHttpResponse.body || ''
@@ -79,7 +89,7 @@ function makeGotMockValueFromPromise (promise) {
79
89
  return mockValue
80
90
  }
81
91
 
82
- function makeGotMockValue (body, status, callback) {
92
+ function makeNodeFetchMockValue (body, status, callback) {
83
93
  const mockValue = new Promise(resolve => {
84
94
  // setTimeout is used so that this promise does not synchronously resolve
85
95
  // because unmocked got will NEVER return synchronously. This ensures
@@ -114,7 +124,7 @@ function mockNodeFetch () {
114
124
  })
115
125
 
116
126
  nodeFetchMock.mockResp = (body = '', statusCode = 200, callback) => {
117
- nodeFetchMock.mockReturnValue(makeGotMockValue(body, statusCode, callback))
127
+ nodeFetchMock.mockReturnValue(makeNodeFetchMockValue(body, statusCode, callback))
118
128
  }
119
129
 
120
130
  /**
@@ -130,14 +140,14 @@ function mockNodeFetch () {
130
140
  for (const callback of callbacks) {
131
141
  const desiredHTTPResponse = callback(request)
132
142
  if (desiredHTTPResponse === true) {
133
- const unmockedGot = jest.requireActual('../src/got')
134
- return unmockedGot(url, options)
143
+ const unmockedFetch = jest.requireActual('../src/got')
144
+ return unmockedFetch(url, options)
135
145
  }
136
146
  if (desiredHTTPResponse) {
137
147
  if (desiredHTTPResponse.then) {
138
- return makeGotMockValueFromPromise(desiredHTTPResponse)
148
+ return makeNodeFetchMockValueFromPromise(desiredHTTPResponse)
139
149
  }
140
- return makeGotMockValue(
150
+ return makeNodeFetchMockValue(
141
151
  // follows the names from supertest
142
152
  desiredHTTPResponse.text || desiredHTTPResponse.body || '',
143
153
  desiredHTTPResponse.status || 200)
@@ -167,6 +177,5 @@ function mockNodeFetch () {
167
177
  export {
168
178
  BaseAppTest,
169
179
  BaseTest,
170
- mockNodeFetch,
171
180
  runTests
172
181
  }