File tree Expand file tree Collapse file tree 4 files changed +34
-9
lines changed Expand file tree Collapse file tree 4 files changed +34
-9
lines changed Original file line number Diff line number Diff line change
1
+ name : Node.js CI
2
+
3
+ on : [push]
4
+
5
+ jobs :
6
+ build :
7
+
8
+ runs-on : ubuntu-latest
9
+
10
+ steps :
11
+ - uses : actions/checkout@v4
12
+ - name : Use Node.js
13
+ uses : actions/setup-node@v4
14
+ with :
15
+ node-version : ' 22.x'
16
+ - run : npm ci
17
+ - run : npm run build --if-present
18
+ - run : npm test
Original file line number Diff line number Diff line change @@ -73,12 +73,15 @@ export default async function (fastify) {
73
73
schema : schema [ '/courses/{id}' ] . PATCH . args . properties ,
74
74
} ,
75
75
async ( request ) => {
76
- // fastify.assert.equal(a, b, 403)
77
- const course = await db . update ( schemas . courses )
76
+ const course = await db . query . courses . findFirst ( {
77
+ where : eq ( schemas . courses . id , request . params . id ) ,
78
+ } )
79
+ fastify . assert ( course , 404 )
80
+
81
+ fastify . assert . equal ( request . user . id , course ?. creatorId , 403 )
82
+ await db . update ( schemas . courses )
78
83
. set ( request . body )
79
84
. where ( eq ( schemas . courses . id , request . params . id ) )
80
- . returning ( )
81
- fastify . assert ( course , 404 )
82
85
83
86
return { id : request . params . id }
84
87
} ,
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ import assert from 'assert'
5
5
import helper from 'fastify-cli/helper.js'
6
6
import path from 'path'
7
7
import { fileURLToPath } from 'url'
8
+ import * as schemas from '../db/schema.js'
9
+ import { eq } from 'drizzle-orm'
8
10
9
11
const __filename = fileURLToPath ( import . meta. url )
10
12
const __dirname = path . dirname ( __filename )
@@ -49,10 +51,12 @@ async function build(t) {
49
51
}
50
52
51
53
/**
52
- * @param {import('fastify').FastifyInstance } app
53
- */
54
- async function getAuthHeader ( app ) {
55
- const client = await app . db . query . users . findFirst ( )
54
+ * @param {import('fastify').FastifyInstance } app
55
+ * @param {number | null } userId
56
+ */
57
+ async function getAuthHeader ( app , userId = null ) {
58
+ const from = app . db . select ( ) . from ( schemas . users )
59
+ const [ client ] = userId ? await from . where ( eq ( schemas . users . id , userId ) ) : await from . limit ( 1 )
56
60
assert . ok ( client )
57
61
const token = app . jwt . sign ( { id : client . id } )
58
62
return {
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ test('patch courses/:id', async (t) => {
47
47
const course = await app . db . query . courses . findFirst ( )
48
48
assert . ok ( course )
49
49
50
- const authHeader = await getAuthHeader ( app )
50
+ const authHeader = await getAuthHeader ( app , course . creatorId )
51
51
const res = await app . inject ( {
52
52
method : 'patch' ,
53
53
url : `/api/courses/${ course . id } ` ,
You can’t perform that action at this time.
0 commit comments