@platformatic/db-core 0.46.1 → 0.46.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/db-core",
3
- "version": "0.46.1",
3
+ "version": "0.46.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -22,10 +22,10 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "fastify-plugin": "^4.5.0",
25
- "@platformatic/sql-events": "0.46.1",
26
- "@platformatic/sql-graphql": "0.46.1",
27
- "@platformatic/sql-mapper": "0.46.1",
28
- "@platformatic/sql-openapi": "0.46.1"
25
+ "@platformatic/sql-events": "0.46.2",
26
+ "@platformatic/sql-graphql": "0.46.2",
27
+ "@platformatic/sql-mapper": "0.46.2",
28
+ "@platformatic/sql-openapi": "0.46.2"
29
29
  },
30
30
  "scripts": {
31
31
  "test": "standard | snazzy && tap test/*test.js",
@@ -1,224 +0,0 @@
1
- 'use strict'
2
-
3
- const { test } = require('tap')
4
- const Fastify = require('fastify')
5
- const { clear, connInfo } = require('./helper')
6
- const core = require('..')
7
- const { once } = require('events')
8
-
9
- async function createBasicPages (db, sql) {
10
- if (module.exports.isSQLite) {
11
- await db.query(sql`CREATE TABLE pages (
12
- id INTEGER PRIMARY KEY,
13
- title VARCHAR(42)
14
- );`)
15
- } else {
16
- await db.query(sql`CREATE TABLE pages (
17
- id SERIAL PRIMARY KEY,
18
- title VARCHAR(42)
19
- );`)
20
- }
21
- }
22
-
23
- async function onDatabaseLoad (db, sql) {
24
- await clear(db, sql)
25
- await createBasicPages(db, sql)
26
- }
27
-
28
- test('entities are available', async ({ ok, teardown }) => {
29
- const app = Fastify({
30
- pluginTimeout: 30000
31
- })
32
- app.register(core, {
33
- ...connInfo,
34
- onDatabaseLoad
35
- })
36
- teardown(() => app.close())
37
-
38
- await app.ready()
39
- ok(app.platformatic.entities.page)
40
- })
41
-
42
- test('graphql is available', async ({ equal, same, teardown }) => {
43
- const app = Fastify({
44
- pluginTimeout: 30000
45
- })
46
- app.register(core, {
47
- ...connInfo,
48
- onDatabaseLoad
49
- })
50
- teardown(() => app.close())
51
-
52
- const res = await app.inject({
53
- method: 'POST',
54
- url: '/graphql',
55
- body: {
56
- query: `
57
- mutation {
58
- savePage(input: { title: "Hello" }) {
59
- id
60
- title
61
- }
62
- }
63
- `
64
- }
65
- })
66
- equal(res.statusCode, 200, 'savePage status code')
67
- same(res.json(), {
68
- data: {
69
- savePage: {
70
- id: 1,
71
- title: 'Hello'
72
- }
73
- }
74
- }, 'savePage response')
75
- })
76
-
77
- test('graphiql can be enabled', async ({ equal, same, teardown }) => {
78
- const app = Fastify({
79
- pluginTimeout: 30000
80
- })
81
- app.register(core, {
82
- ...connInfo,
83
- onDatabaseLoad,
84
- graphql: {
85
- graphiql: true
86
- }
87
- })
88
- teardown(() => app.close())
89
-
90
- const res = await app.inject({
91
- method: 'GET',
92
- url: '/graphiql'
93
- })
94
- equal(res.statusCode, 200, 'savePage status code')
95
- })
96
-
97
- test('graphql can be disabled', async ({ equal, teardown }) => {
98
- const app = Fastify({
99
- pluginTimeout: 30000
100
- })
101
- app.register(core, {
102
- ...connInfo,
103
- onDatabaseLoad,
104
- graphql: false
105
- })
106
- teardown(() => app.close())
107
-
108
- const res = await app.inject({
109
- method: 'POST',
110
- url: '/graphql',
111
- body: {
112
- query: `
113
- mutation {
114
- savePage(input: { title: "Hello" }) {
115
- id
116
- title
117
- }
118
- }
119
- `
120
- }
121
- })
122
- equal(res.statusCode, 404, '/graphql not found')
123
- })
124
-
125
- test('openapi is available', async ({ equal, teardown }) => {
126
- const app = Fastify({
127
- pluginTimeout: 30000
128
- })
129
- app.register(core, {
130
- ...connInfo,
131
- onDatabaseLoad
132
- })
133
- teardown(() => app.close())
134
-
135
- const res = await app.inject({
136
- method: 'GET',
137
- url: '/pages'
138
- })
139
- equal(res.statusCode, 200, '/pages status code')
140
- })
141
-
142
- test('openapi can be disabled', async ({ equal, teardown }) => {
143
- const app = Fastify({
144
- pluginTimeout: 30000
145
- })
146
- app.register(core, {
147
- ...connInfo,
148
- onDatabaseLoad,
149
- openapi: false
150
- })
151
- teardown(() => app.close())
152
-
153
- const res = await app.inject({
154
- method: 'GET',
155
- url: '/pages'
156
- })
157
- equal(res.statusCode, 404, '/pages status code')
158
- })
159
-
160
- test('openapi with an object', async ({ equal, teardown }) => {
161
- const app = Fastify({
162
- pluginTimeout: 30000
163
- })
164
- app.register(core, {
165
- ...connInfo,
166
- onDatabaseLoad,
167
- openapi: {}
168
- })
169
- teardown(() => app.close())
170
-
171
- const res = await app.inject({
172
- method: 'GET',
173
- url: '/pages'
174
- })
175
- equal(res.statusCode, 200, '/pages status code')
176
- })
177
-
178
- test('mq is available', async ({ equal, same, teardown }) => {
179
- const app = Fastify({
180
- pluginTimeout: 30000
181
- })
182
- await app.register(core, {
183
- ...connInfo,
184
- events: true,
185
- onDatabaseLoad
186
- })
187
- teardown(() => app.close())
188
-
189
- const queue = await app.platformatic.subscribe([
190
- await app.platformatic.entities.page.getSubscriptionTopic({ action: 'save' })
191
- ])
192
-
193
- const res = await app.inject({
194
- method: 'POST',
195
- url: '/graphql',
196
- body: {
197
- query: `
198
- mutation {
199
- savePage(input: { title: "Hello" }) {
200
- id
201
- title
202
- }
203
- }
204
- `
205
- }
206
- })
207
- equal(res.statusCode, 200, 'savePage status code')
208
- same(res.json(), {
209
- data: {
210
- savePage: {
211
- id: 1,
212
- title: 'Hello'
213
- }
214
- }
215
- }, 'savePage response')
216
-
217
- const [ev] = await once(queue, 'data')
218
- same(ev, {
219
- topic: '/entity/page/save/1',
220
- payload: {
221
- id: 1
222
- }
223
- })
224
- })
package/test/helper.js DELETED
@@ -1,58 +0,0 @@
1
- 'use strict'
2
-
3
- const why = require('why-is-node-running')
4
-
5
- // This file must be required/imported as the first file
6
- // in the test suite. It sets up the global environment
7
- // to track the open handles via why-is-node-running.
8
- setInterval(() => {
9
- why()
10
- }, 10000).unref()
11
-
12
- // Needed to work with dates & postgresql
13
- // See https://node-postgres.com/features/types/
14
- process.env.TZ = 'UTC'
15
-
16
- const connInfo = {}
17
-
18
- if (!process.env.DB || process.env.DB === 'postgresql') {
19
- connInfo.connectionString = 'postgres://postgres:postgres@127.0.0.1/postgres'
20
- module.exports.isPg = true
21
- } else if (process.env.DB === 'mariadb') {
22
- connInfo.connectionString = 'mysql://root@127.0.0.1:3307/graph'
23
- connInfo.poolSize = 10
24
- module.exports.isMysql = true
25
- } else if (process.env.DB === 'mysql') {
26
- connInfo.connectionString = 'mysql://root@127.0.0.1/graph'
27
- connInfo.poolSize = 10
28
- module.exports.isMysql = true
29
- } else if (process.env.DB === 'mysql8') {
30
- connInfo.connectionString = 'mysql://root@127.0.0.1:3308/graph'
31
- connInfo.poolSize = 10
32
- module.exports.isMysql = true
33
- } else if (process.env.DB === 'sqlite') {
34
- connInfo.connectionString = 'sqlite://:memory:'
35
- module.exports.isSQLite = true
36
- }
37
-
38
- module.exports.connInfo = connInfo
39
-
40
- module.exports.clear = async function (db, sql) {
41
- try {
42
- await db.query(sql`DROP TABLE pages`)
43
- } catch (err) {
44
- }
45
- }
46
-
47
- function buildConfig (options) {
48
- const base = {
49
- server: {},
50
- core: {},
51
- cli: {},
52
- authorization: {}
53
- }
54
-
55
- return Object.assign(base, options)
56
- }
57
-
58
- module.exports.buildConfig = buildConfig