@webjskit/cli 0.4.1 → 0.4.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/lib/create.js +21 -0
- package/lib/saas-template.js +48 -0
- package/package.json +1 -1
package/lib/create.js
CHANGED
|
@@ -266,6 +266,27 @@ export async function POST(req: Request) {
|
|
|
266
266
|
const body = await req.json();
|
|
267
267
|
return Response.json(await createUser(body));
|
|
268
268
|
}
|
|
269
|
+
`);
|
|
270
|
+
// Minimal test stub so the scaffold passes `webjs check` (tests-exist)
|
|
271
|
+
// and `webjs test` runs cleanly. Replace these with real assertions
|
|
272
|
+
// once you wire the action/query to a real data source.
|
|
273
|
+
await writeFile(join(appDir, 'test', 'unit', 'users.test.ts'), `import { test } from 'node:test';
|
|
274
|
+
import assert from 'node:assert/strict';
|
|
275
|
+
|
|
276
|
+
import { listUsers } from '../../modules/users/queries/list-users.server.ts';
|
|
277
|
+
import { createUser } from '../../modules/users/actions/create-user.server.ts';
|
|
278
|
+
|
|
279
|
+
test('listUsers returns an array', async () => {
|
|
280
|
+
const users = await listUsers();
|
|
281
|
+
assert.ok(Array.isArray(users));
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test('createUser returns a success envelope with the input echoed back', async () => {
|
|
285
|
+
const result = await createUser({ name: 'Test', email: 'test@example.com' });
|
|
286
|
+
assert.equal(result.success, true);
|
|
287
|
+
assert.equal(result.data.name, 'Test');
|
|
288
|
+
assert.equal(result.data.email, 'test@example.com');
|
|
289
|
+
});
|
|
269
290
|
`);
|
|
270
291
|
await writeFile(join(appDir, 'modules', 'users', 'types.ts'), `export interface User {
|
|
271
292
|
id: string;
|
package/lib/saas-template.js
CHANGED
|
@@ -133,6 +133,54 @@ export async function writeSaasFiles(appDir) {
|
|
|
133
133
|
"",
|
|
134
134
|
].join('\n'));
|
|
135
135
|
|
|
136
|
+
// test/unit/auth.test.ts — minimal stub so the scaffold passes
|
|
137
|
+
// `webjs check` (tests-exist) and `webjs test` runs cleanly out of the
|
|
138
|
+
// box. The signup/current-user functions import from lib/prisma.ts and
|
|
139
|
+
// lib/auth.ts, both of which need `prisma generate` to have run before
|
|
140
|
+
// they can be imported — so we deliberately test only the runtime-
|
|
141
|
+
// dependency-free types.ts here. Replace with real tests once Prisma
|
|
142
|
+
// is set up (run `npm install && npx prisma migrate dev --name init`).
|
|
143
|
+
await writeFile(join(appDir, 'test', 'unit', 'auth.test.ts'), [
|
|
144
|
+
"import { test } from 'node:test';",
|
|
145
|
+
"import assert from 'node:assert/strict';",
|
|
146
|
+
"",
|
|
147
|
+
"import type { User, ActionResult } from '../../modules/auth/types.ts';",
|
|
148
|
+
"",
|
|
149
|
+
"test('User shape: id is numeric, email is required', () => {",
|
|
150
|
+
" const u: User = { id: 1, name: 'Test', email: 'test@example.com' };",
|
|
151
|
+
" assert.equal(typeof u.id, 'number');",
|
|
152
|
+
" assert.equal(typeof u.email, 'string');",
|
|
153
|
+
"});",
|
|
154
|
+
"",
|
|
155
|
+
"test('ActionResult: success envelope carries data', () => {",
|
|
156
|
+
" const r: ActionResult<User> = {",
|
|
157
|
+
" success: true,",
|
|
158
|
+
" data: { id: 1, name: 'Test', email: 'test@example.com' },",
|
|
159
|
+
" };",
|
|
160
|
+
" assert.equal(r.success, true);",
|
|
161
|
+
" if (r.success) assert.equal(r.data.email, 'test@example.com');",
|
|
162
|
+
"});",
|
|
163
|
+
"",
|
|
164
|
+
"test('ActionResult: failure envelope carries error + status', () => {",
|
|
165
|
+
" const r: ActionResult<User> = {",
|
|
166
|
+
" success: false,",
|
|
167
|
+
" error: 'Email already registered',",
|
|
168
|
+
" status: 409,",
|
|
169
|
+
" };",
|
|
170
|
+
" assert.equal(r.success, false);",
|
|
171
|
+
" if (!r.success) {",
|
|
172
|
+
" assert.equal(r.status, 409);",
|
|
173
|
+
" assert.ok(r.error.length > 0);",
|
|
174
|
+
" }",
|
|
175
|
+
"});",
|
|
176
|
+
"",
|
|
177
|
+
"// TODO: once you've run `npm install && npx prisma migrate dev` you can",
|
|
178
|
+
"// import { signup } from '../../modules/auth/actions/signup.server.ts'",
|
|
179
|
+
"// and { currentUser } from '../../modules/auth/queries/current-user.server.ts'",
|
|
180
|
+
"// and write real integration tests against a test SQLite DB.",
|
|
181
|
+
"",
|
|
182
|
+
].join('\n'));
|
|
183
|
+
|
|
136
184
|
// app/api/auth/[...path]/route.ts
|
|
137
185
|
await mkdir(join(appDir, 'app', 'api', 'auth', '[...path]'), { recursive: true });
|
|
138
186
|
await writeFile(join(appDir, 'app', 'api', 'auth', '[...path]', 'route.ts'), [
|