@forklaunch/express 0.1.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.
@@ -0,0 +1,137 @@
1
+ import { TypeboxSchemaValidator, string } from "@forklaunch/validator/typebox";
2
+ import { killPortProcess } from "kill-port-process";
3
+ import forklaunchExpress, { Application, Router, forklaunchRouter } from "../forklaunch.express";
4
+
5
+ const typeboxSchemaValidator = new TypeboxSchemaValidator();
6
+
7
+ describe('Forklaunch Express Tests', () => {
8
+ let forklaunchApplication: Application<TypeboxSchemaValidator>;
9
+ let forklaunchRouterInstance: Router<TypeboxSchemaValidator>;
10
+
11
+ beforeAll(async () => {
12
+ await killPortProcess(6934);
13
+
14
+ forklaunchApplication = forklaunchExpress(typeboxSchemaValidator);
15
+ forklaunchRouterInstance = forklaunchRouter('/testpath', typeboxSchemaValidator);
16
+
17
+ forklaunchRouterInstance.get('/test', {
18
+ name: 'Test',
19
+ summary: 'Test Summary',
20
+ responses: {
21
+ 200: string
22
+ }
23
+ }, (req, res) => {
24
+ res.status(200).send('Hello World');
25
+ });
26
+
27
+ forklaunchRouterInstance.post('/test', {
28
+ name: 'Test',
29
+ summary: 'Test Summary',
30
+ body: {
31
+ test: string
32
+ },
33
+ responses: {
34
+ 200: string
35
+ }
36
+ }, (req, res) => {
37
+ res.status(200).send(req.body.test);
38
+ });
39
+
40
+ forklaunchRouterInstance.put('/test', {
41
+ name: 'Test',
42
+ summary: 'Test Summary',
43
+ body: {
44
+ test: string
45
+ },
46
+ responses: {
47
+ 200: string
48
+ }
49
+ }, (req, res) => {
50
+ res.status(200).send(req.body.test);
51
+ });
52
+
53
+ forklaunchRouterInstance.patch('/test', {
54
+ name: 'Test',
55
+ summary: 'Test Summary',
56
+ body: {
57
+ test: string
58
+ },
59
+ responses: {
60
+ 200: string
61
+ }
62
+ }, (req, res) => {
63
+ res.status(200).send(req.body.test);
64
+ });
65
+
66
+ forklaunchRouterInstance.delete('/test', {
67
+ name: 'Test',
68
+ summary: 'Test Summary',
69
+ responses: {
70
+ 200: string
71
+ }
72
+ }, (req, res) => {
73
+ res.status(200).send('Hello World');
74
+ });
75
+
76
+ forklaunchApplication.use(forklaunchRouterInstance);
77
+
78
+ await forklaunchApplication.listen(6934, () => {
79
+ console.log('Server started');
80
+ });
81
+ });
82
+
83
+ test('Get', async () => {
84
+ const testGet = await fetch('http://localhost:6934/testpath/test', {
85
+ method: 'GET'
86
+ });
87
+
88
+ expect(testGet.status).toBe(200);
89
+ expect(await testGet.text()).toBe('Hello World');
90
+ });
91
+
92
+ test('Post', async () => {
93
+ const testPost = await fetch('http://localhost:6934/testpath/test', {
94
+ method: 'POST',
95
+ body: JSON.stringify({ test: 'Hello World' }),
96
+ headers: { 'Content-Type': 'application/json' }
97
+ });
98
+
99
+ expect(testPost.status).toBe(200);
100
+ expect(await testPost.text()).toBe('Hello World');
101
+ });
102
+
103
+ test('Put', async () => {
104
+ const testPut = await fetch('http://localhost:6934/testpath/test', {
105
+ method: 'PUT',
106
+ body: JSON.stringify({ test: 'Hello World' }),
107
+ headers: { 'Content-Type': 'application/json' }
108
+ });
109
+
110
+ expect(testPut.status).toBe(200);
111
+ expect(await testPut.text()).toBe('Hello World');
112
+ });
113
+
114
+ test('Patch', async () => {
115
+ const testPatch = await fetch('http://localhost:6934/testpath/test', {
116
+ method: 'PATCH',
117
+ body: JSON.stringify({ test: 'Hello World' }),
118
+ headers: { 'Content-Type': 'application/json' }
119
+ });
120
+
121
+ expect(testPatch.status).toBe(200);
122
+ expect(await testPatch.text()).toBe('Hello World');
123
+ });
124
+
125
+ test('Delete', async () => {
126
+ const testDelete = await fetch('http://localhost:6934/testpath/test', {
127
+ method: 'DELETE'
128
+ });
129
+
130
+ expect(testDelete.status).toBe(200);
131
+ expect(await testDelete.text()).toBe('Hello World');
132
+ });
133
+
134
+ afterAll(async () => {
135
+ setTimeout(async () => await killPortProcess(6934), 500);
136
+ });
137
+ });
@@ -0,0 +1,137 @@
1
+ import { ZodSchemaValidator, string } from "@forklaunch/validator/zod";
2
+ import { killPortProcess } from "kill-port-process";
3
+ import forklaunchExpress, { Application, Router, forklaunchRouter } from "../forklaunch.express";
4
+
5
+ const zodSchemaValidator = new ZodSchemaValidator();
6
+
7
+ describe('Forklaunch Express Tests', () => {
8
+ let forklaunchApplication: Application<ZodSchemaValidator>;
9
+ let forklaunchRouterInstance: Router<ZodSchemaValidator>;
10
+
11
+ beforeAll(async () => {
12
+ await killPortProcess(6935);
13
+
14
+ forklaunchApplication = forklaunchExpress(zodSchemaValidator);
15
+ forklaunchRouterInstance = forklaunchRouter('/testpath', zodSchemaValidator);
16
+
17
+ forklaunchRouterInstance.get('/test', {
18
+ name: 'Test',
19
+ summary: 'Test Summary',
20
+ responses: {
21
+ 200: string
22
+ }
23
+ }, (req, res) => {
24
+ res.status(200).send('Hello World');
25
+ });
26
+
27
+ forklaunchRouterInstance.post('/test', {
28
+ name: 'Test',
29
+ summary: 'Test Summary',
30
+ body: {
31
+ test: string
32
+ },
33
+ responses: {
34
+ 200: string
35
+ }
36
+ }, (req, res) => {
37
+ res.status(200).send(req.body.test);
38
+ });
39
+
40
+ forklaunchRouterInstance.put('/test', {
41
+ name: 'Test',
42
+ summary: 'Test Summary',
43
+ body: {
44
+ test: string
45
+ },
46
+ responses: {
47
+ 200: string
48
+ }
49
+ }, (req, res) => {
50
+ res.status(200).send(req.body.test);
51
+ });
52
+
53
+ forklaunchRouterInstance.patch('/test', {
54
+ name: 'Test',
55
+ summary: 'Test Summary',
56
+ body: {
57
+ test: string
58
+ },
59
+ responses: {
60
+ 200: string
61
+ }
62
+ }, (req, res) => {
63
+ res.status(200).send(req.body.test);
64
+ });
65
+
66
+ forklaunchRouterInstance.delete('/test', {
67
+ name: 'Test',
68
+ summary: 'Test Summary',
69
+ responses: {
70
+ 200: string
71
+ }
72
+ }, (req, res) => {
73
+ res.status(200).send('Hello World');
74
+ });
75
+
76
+ forklaunchApplication.use(forklaunchRouterInstance);
77
+
78
+ await forklaunchApplication.listen(6935, () => {
79
+ console.log('Server started');
80
+ });
81
+ });
82
+
83
+ test('Get', async () => {
84
+ const testGet = await fetch('http://localhost:6934/testpath/test', {
85
+ method: 'GET'
86
+ });
87
+
88
+ expect(testGet.status).toBe(200);
89
+ expect(await testGet.text()).toBe('Hello World');
90
+ });
91
+
92
+ test('Post', async () => {
93
+ const testPost = await fetch('http://localhost:6934/testpath/test', {
94
+ method: 'POST',
95
+ body: JSON.stringify({ test: 'Hello World' }),
96
+ headers: { 'Content-Type': 'application/json' }
97
+ });
98
+
99
+ expect(testPost.status).toBe(200);
100
+ expect(await testPost.text()).toBe('Hello World');
101
+ });
102
+
103
+ test('Put', async () => {
104
+ const testPut = await fetch('http://localhost:6934/testpath/test', {
105
+ method: 'PUT',
106
+ body: JSON.stringify({ test: 'Hello World' }),
107
+ headers: { 'Content-Type': 'application/json' }
108
+ });
109
+
110
+ expect(testPut.status).toBe(200);
111
+ expect(await testPut.text()).toBe('Hello World');
112
+ });
113
+
114
+ test('Patch', async () => {
115
+ const testPatch = await fetch('http://localhost:6934/testpath/test', {
116
+ method: 'PATCH',
117
+ body: JSON.stringify({ test: 'Hello World' }),
118
+ headers: { 'Content-Type': 'application/json' }
119
+ });
120
+
121
+ expect(testPatch.status).toBe(200);
122
+ expect(await testPatch.text()).toBe('Hello World');
123
+ });
124
+
125
+ test('Delete', async () => {
126
+ const testDelete = await fetch('http://localhost:6934/testpath/test', {
127
+ method: 'DELETE'
128
+ });
129
+
130
+ expect(testDelete.status).toBe(200);
131
+ expect(await testDelete.text()).toBe('Hello World');
132
+ });
133
+
134
+ afterAll(async () => {
135
+ setTimeout(async () => await killPortProcess(6935), 500);
136
+ });
137
+ });