@lobb-js/lobb-ext-storage 0.13.1 → 0.15.0

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.
@@ -1,208 +0,0 @@
1
- import { Lobb } from "@lobb-js/core";
2
- import { afterAll, beforeAll, describe, expect, it } from "bun:test";
3
- import { readFileSync } from "node:fs";
4
- import { createSimpleConfig } from "./configs/simple.ts";
5
-
6
- describe("Recursive Delete Many", () => {
7
- let lobb: Lobb;
8
- let baseUrl: string;
9
- let directoryEntryId: string;
10
- let fileEntryId: string;
11
-
12
- beforeAll(async () => {
13
- const config = createSimpleConfig();
14
- lobb = await Lobb.init(config);
15
- baseUrl = `http://127.0.0.1:${lobb.webServer.port}`;
16
- });
17
-
18
- afterAll(async () => {
19
- await lobb.close();
20
- });
21
-
22
- it("should create a directory successfully", async () => {
23
- const response = await fetch(
24
- `${baseUrl}/api/collections/storage_fs`,
25
- {
26
- method: "POST",
27
- body: JSON.stringify({
28
- data: {
29
- name: "test",
30
- path: "/",
31
- },
32
- }),
33
- },
34
- );
35
- const data = await response.json();
36
-
37
- expect(data).toMatchObject({
38
- data: {
39
- name: "test",
40
- path: "/",
41
- type: "directory",
42
- },
43
- });
44
-
45
- directoryEntryId = data.data.id;
46
- });
47
-
48
- it("should create a directory inside that directory successfully", async () => {
49
- const response = await fetch(
50
- `${baseUrl}/api/collections/storage_fs`,
51
- {
52
- method: "POST",
53
- body: JSON.stringify({
54
- data: {
55
- name: "nested_test",
56
- path: "/test",
57
- },
58
- }),
59
- },
60
- );
61
- const data = await response.json();
62
-
63
- expect(data).toMatchObject({
64
- data: {
65
- name: "nested_test",
66
- path: "/test",
67
- type: "directory",
68
- },
69
- });
70
- });
71
-
72
- it("should upload a file inside the test directory successfully", async () => {
73
- const image = readFileSync(import.meta.dirname + "/files/rose.jpeg");
74
- const imageFileName = "rose.jpeg";
75
-
76
- const formData = new FormData();
77
- formData.append(
78
- "file",
79
- new Blob([image]),
80
- imageFileName,
81
- );
82
- formData.append("path", "/test/nested_test");
83
-
84
- const response = await fetch(
85
- `${baseUrl}/api/collections/storage_fs`,
86
- {
87
- method: "POST",
88
- body: formData,
89
- },
90
- );
91
- const data = await response.json();
92
-
93
- expect(data).toMatchObject({
94
- data: {
95
- name: "rose.jpeg",
96
- path: "/test/nested_test",
97
- type: "file",
98
- file_mime_type: "image/jpeg",
99
- file_size: "1086103",
100
- },
101
- });
102
-
103
- fileEntryId = data.data.id;
104
- });
105
-
106
- it("should list all available entries", async () => {
107
- const response = await fetch(
108
- `${baseUrl}/api/collections/storage_fs?sort=id`,
109
- {
110
- method: "GET",
111
- },
112
- );
113
- const data = await response.json();
114
-
115
- expect(data).toMatchObject({
116
- data: [
117
- {
118
- name: "test",
119
- path: "/",
120
- type: "directory",
121
- icon: null,
122
- },
123
- {
124
- name: "nested_test",
125
- path: "/test",
126
- type: "directory",
127
- icon: null,
128
- },
129
- {
130
- path: "/test/nested_test",
131
- name: "rose.jpeg",
132
- type: "file",
133
- file_mime_type: "image/jpeg",
134
- file_size: "1086103",
135
- icon: null,
136
- },
137
- ],
138
- meta: {
139
- totalCount: 3,
140
- },
141
- });
142
- });
143
-
144
- it("removing the test directory should remove everything inside it too", async () => {
145
- const response = await fetch(
146
- `${baseUrl}/api/collections/storage_fs`,
147
- {
148
- method: "DELETE",
149
- body: JSON.stringify({
150
- filter: {
151
- id: {
152
- $in: [directoryEntryId],
153
- },
154
- },
155
- }),
156
- },
157
- );
158
- const data = await response.json();
159
-
160
- expect(data).toEqual({
161
- affectedCount: 1,
162
- });
163
-
164
- const response1 = await fetch(
165
- `${baseUrl}/api/collections/storage_fs`,
166
- {
167
- method: "GET",
168
- },
169
- );
170
- const data1 = await response1.json();
171
-
172
- expect(data1).toMatchObject({
173
- data: [],
174
- meta: {
175
- totalCount: 0,
176
- },
177
- });
178
- });
179
-
180
- it("shouldnt be able to get the content of the removed file using deleteMany", async () => {
181
- const response = await fetch(
182
- `${baseUrl}/api/collections/storage_fs/${fileEntryId}?action=view`,
183
- {
184
- method: "GET",
185
- },
186
- );
187
- await response.json();
188
-
189
- expect(response.status).toBe(404);
190
- });
191
-
192
- it("should list an empty array since all entries are removed", async () => {
193
- const response = await fetch(
194
- `${baseUrl}/api/collections/storage_fs`,
195
- {
196
- method: "GET",
197
- },
198
- );
199
- const data = await response.json();
200
-
201
- expect(data).toMatchObject({
202
- data: [],
203
- meta: {
204
- totalCount: 0,
205
- },
206
- });
207
- });
208
- });
@@ -1,206 +0,0 @@
1
- import { Lobb } from "@lobb-js/core";
2
- import { afterAll, beforeAll, describe, expect, it } from "bun:test";
3
- import { readFileSync } from "node:fs";
4
- import { createSimpleConfig } from "./configs/simple.ts";
5
-
6
- describe("Recursive Delete One", () => {
7
- let lobb: Lobb;
8
- let baseUrl: string;
9
- let directoryEntryId: string;
10
- let fileEntryId: string;
11
-
12
- beforeAll(async () => {
13
- const config = createSimpleConfig();
14
- lobb = await Lobb.init(config);
15
- baseUrl = `http://127.0.0.1:${lobb.webServer.port}`;
16
- });
17
-
18
- afterAll(async () => {
19
- await lobb.close();
20
- });
21
-
22
- it("Should create a directory successfully", async () => {
23
- const response = await fetch(
24
- `${baseUrl}/api/collections/storage_fs`,
25
- {
26
- method: "POST",
27
- body: JSON.stringify({
28
- data: {
29
- name: "test",
30
- path: "/",
31
- },
32
- }),
33
- },
34
- );
35
- const data = await response.json();
36
-
37
- expect(data).toMatchObject({
38
- data: {
39
- name: "test",
40
- path: "/",
41
- type: "directory",
42
- },
43
- });
44
-
45
- directoryEntryId = data.data.id;
46
- });
47
-
48
- it("should create a directory inside that directory successfully", async () => {
49
- const response = await fetch(
50
- `${baseUrl}/api/collections/storage_fs`,
51
- {
52
- method: "POST",
53
- body: JSON.stringify({
54
- data: {
55
- name: "nested_test",
56
- path: "/test",
57
- },
58
- }),
59
- },
60
- );
61
- const data = await response.json();
62
-
63
- expect(data).toMatchObject({
64
- data: {
65
- name: "nested_test",
66
- path: "/test",
67
- type: "directory",
68
- },
69
- });
70
- });
71
-
72
- it("should upload a file inside the test directory successfully", async () => {
73
- const image = readFileSync(import.meta.dirname + "/files/rose.jpeg");
74
- const imageFileName = "rose.jpeg";
75
-
76
- const formData = new FormData();
77
- formData.append(
78
- "file",
79
- new Blob([image]),
80
- imageFileName,
81
- );
82
- formData.append("path", "/test/nested_test");
83
-
84
- const response = await fetch(
85
- `${baseUrl}/api/collections/storage_fs`,
86
- {
87
- method: "POST",
88
- body: formData,
89
- },
90
- );
91
- const data = await response.json();
92
-
93
- expect(data).toMatchObject({
94
- data: {
95
- name: "rose.jpeg",
96
- path: "/test/nested_test",
97
- type: "file",
98
- file_mime_type: "image/jpeg",
99
- file_size: "1086103",
100
- },
101
- });
102
-
103
- fileEntryId = data.data.id;
104
- });
105
-
106
- it("should list all available entries", async () => {
107
- const response = await fetch(
108
- `${baseUrl}/api/collections/storage_fs?sort=id`,
109
- {
110
- method: "GET",
111
- },
112
- );
113
- const data = await response.json();
114
-
115
- expect(data).toMatchObject({
116
- data: [
117
- {
118
- name: "test",
119
- path: "/",
120
- type: "directory",
121
- icon: null,
122
- },
123
- {
124
- name: "nested_test",
125
- path: "/test",
126
- type: "directory",
127
- icon: null,
128
- },
129
- {
130
- path: "/test/nested_test",
131
- name: "rose.jpeg",
132
- type: "file",
133
- icon: null,
134
- file_mime_type: "image/jpeg",
135
- file_size: "1086103",
136
- },
137
- ],
138
- meta: {
139
- totalCount: 3,
140
- },
141
- });
142
- });
143
-
144
- it("removing the test directory should remove everything inside it too", async () => {
145
- const response = await fetch(
146
- `${baseUrl}/api/collections/storage_fs/${directoryEntryId}`,
147
- {
148
- method: "DELETE",
149
- },
150
- );
151
- const data = await response.json();
152
-
153
- expect(data).toMatchObject({
154
- data: {
155
- path: "/",
156
- name: "test",
157
- type: "directory",
158
- icon: null,
159
- },
160
- });
161
-
162
- const response1 = await fetch(
163
- `${baseUrl}/api/collections/storage_fs`,
164
- {
165
- method: "GET",
166
- },
167
- );
168
- const data1 = await response1.json();
169
-
170
- expect(data1).toMatchObject({
171
- data: [],
172
- meta: {
173
- totalCount: 0,
174
- },
175
- });
176
- });
177
-
178
- it("shouldnt be able to get the content of the removed file using deleteMany", async () => {
179
- const response = await fetch(
180
- `${baseUrl}/api/collections/storage_fs/${fileEntryId}?action=view`,
181
- {
182
- method: "GET",
183
- },
184
- );
185
- await response.json();
186
-
187
- expect(response.status).toBe(404);
188
- });
189
-
190
- it("should list an empty array since all entries are removed", async () => {
191
- const response = await fetch(
192
- `${baseUrl}/api/collections/storage_fs`,
193
- {
194
- method: "GET",
195
- },
196
- );
197
- const data = await response.json();
198
-
199
- expect(data).toMatchObject({
200
- data: [],
201
- meta: {
202
- totalCount: 0,
203
- },
204
- });
205
- });
206
- });