@toa.io/storages.null 0.2.1-dev.3

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 ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@toa.io/storages.null",
3
+ "version": "0.2.1-dev.3",
4
+ "description": "Toa Null Storage Connector",
5
+ "author": "temich <tema.gurtovoy@gmail.com>",
6
+ "homepage": "https://github.com/toa-io/toa#readme",
7
+ "main": "src/index.js",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/toa-io/toa.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/toa-io/toa/issues"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "peerDependencies": {
19
+ "@toa.io/core": "*"
20
+ },
21
+ "scripts": {
22
+ "test": "echo \"Error: run tests from root\" && exit 1"
23
+ }
24
+ }
package/src/factory.js ADDED
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+
3
+ const { Storage } = require('./storage')
4
+
5
+ /**
6
+ * @implements {toa.core.storages.Factory}
7
+ */
8
+ class Factory {
9
+ storage (_) {
10
+ return new Storage()
11
+ }
12
+ }
13
+
14
+ exports.Factory = Factory
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ 'use strict'
2
+
3
+ const { Factory } = require('./factory')
4
+
5
+ exports.Factory = Factory
package/src/storage.js ADDED
@@ -0,0 +1,22 @@
1
+ 'use strict'
2
+
3
+ const { Connector } = require('@toa.io/core')
4
+
5
+ /**
6
+ * @implements {toa.core.Storage}
7
+ */
8
+ class Storage extends Connector {
9
+ async get (_) {
10
+ return null
11
+ }
12
+
13
+ async add (_) {
14
+ return true
15
+ }
16
+
17
+ async store (_) {
18
+ return true
19
+ }
20
+ }
21
+
22
+ exports.Storage = Storage
@@ -0,0 +1,16 @@
1
+ 'use strict'
2
+
3
+ const { Factory } = require('../src/factory')
4
+ const { Storage } = require('../src/storage')
5
+
6
+ let factory
7
+
8
+ beforeAll(() => {
9
+ factory = new Factory()
10
+ })
11
+
12
+ it('should create storage', () => {
13
+ const storage = factory.storage()
14
+
15
+ expect(storage).toBeInstanceOf(Storage)
16
+ })
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ const index = require('../src')
4
+
5
+ it('should export Factory', () => {
6
+ expect(index.Factory).toBeDefined()
7
+ })
@@ -0,0 +1,42 @@
1
+ 'use strict'
2
+
3
+ const { generate } = require('randomstring')
4
+
5
+ const { Storage } = require('../src/storage')
6
+
7
+ let storage
8
+
9
+ beforeAll(() => {
10
+ storage = new Storage()
11
+ })
12
+
13
+ it('should get null', async () => {
14
+ const result = await storage.get()
15
+
16
+ expect(result).toBeNull()
17
+ })
18
+
19
+ it('should add', async () => {
20
+ const object = { id: generate() }
21
+ const result = await storage.add(object)
22
+
23
+ expect(result).toStrictEqual(true)
24
+ })
25
+
26
+ it('should not really add', async () => {
27
+ const object = { id: generate() }
28
+
29
+ await storage.add(object)
30
+
31
+ const result = await storage.get({ query: { id: object.id } })
32
+
33
+ expect(result).toBeNull()
34
+ })
35
+
36
+ it('should store', async () => {
37
+ const object = { id: generate() }
38
+
39
+ const result = await storage.store(object)
40
+
41
+ expect(result).toStrictEqual(true)
42
+ })