-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🎨 Add deces-update index #442
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import { SearchController } from './search.controller'; | ||
import { PersonCompare } from '../models/entities'; | ||
import express from 'express'; | ||
import { describe, expect, it } from 'vitest' | ||
import { initUpdateIndex } from '../updatedIds'; | ||
import { describe, expect, it, beforeAll } from 'vitest' | ||
|
||
beforeAll(async () => { | ||
await initUpdateIndex(); | ||
}) | ||
|
||
describe('search.controller.ts - GET request', () => { | ||
const controller = new SearchController() | ||
|
@@ -90,7 +95,7 @@ describe('search.controller.ts - POST id', () => { | |
it('update id', async () => { | ||
const body = { | ||
'author_id': '[email protected]', | ||
lastName: 'Aiph7u', | ||
lastName: 'Aeboox9e', | ||
proof: 'https://somwhere.in.the.internet', | ||
} | ||
const req = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import { app } from './server'; | ||
import { initUpdateIndex, updateFieldsToIndex, getAllUpdates } from './updatedIds'; | ||
|
||
const port = 8080; | ||
|
||
app.listen( port, () => { | ||
// eslint-disable-next-line no-console | ||
console.log( `server started at http://localhost:${ port }` ); | ||
} ); | ||
(async () => { | ||
await initUpdateIndex(); | ||
const updates = getAllUpdates(); | ||
await updateFieldsToIndex(updates); | ||
|
||
app.listen(port, () => { | ||
// eslint-disable-next-line no-console | ||
console.log(`server started at http://localhost:${port}`); | ||
}); | ||
})(); |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, vu le endpoint updates ! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,18 @@ import { Person } from './models/entities'; | |
import { promisify } from 'util'; | ||
import { parseString } from '@fast-csv/parse'; | ||
import { writeToBuffer } from '@fast-csv/format'; | ||
import { initUpdateIndex } from './updatedIds'; | ||
import fs from "fs"; | ||
import { describe, expect, it, test } from 'vitest' | ||
import { describe, expect, it, test, beforeAll } from 'vitest' | ||
import supertest from 'supertest'; | ||
const server = supertest(app) | ||
const finishedAsync:any = promisify(finished); | ||
|
||
|
||
beforeAll(async () => { | ||
await initUpdateIndex(); | ||
}) | ||
|
||
const csv2Buffer = async (filePath: string, nrows: number) => { | ||
let data = ''; | ||
let index: number; | ||
|
@@ -41,8 +47,8 @@ describe('server.ts - Express application', () => { | |
expect(res.body.msg).toEqual("OK"); | ||
}); | ||
|
||
describe('/id/{id}', () => { | ||
it('search', async () => { | ||
describe.sequential('/id/{id}', () => { | ||
test.sequential('search', async () => { | ||
let res = await server | ||
.get(apiPath('search')) | ||
.query({q: 'Georges Duboeuf'}) | ||
|
@@ -55,19 +61,49 @@ describe('server.ts - Express application', () => { | |
expect(res.body.response.persons[0].links.wikidata).to.include('Q3102639'); | ||
}); | ||
|
||
it('update', async () => { | ||
test.sequential('update add modification to updates', async () => { | ||
const token = await server | ||
.post(apiPath(`auth`)) | ||
.send({user:'[email protected]', password: 'magicPass'}) | ||
const buf = Buffer.from('weird pdf', 'base64') | ||
const res = await server | ||
let res = await server | ||
.post(apiPath(`id/VhfumwT3QnUq`)) | ||
.set('Authorization', `Bearer ${token.body.access_token as string}`) | ||
.field('author_id', '[email protected]') | ||
.field('lastName', 'Aiph7u') | ||
.attach('pdf', buf, 'file.pdf') | ||
expect(res.status).toBe(200); | ||
expect(res.body.msg).to.equal('Update stored'); | ||
|
||
await new Promise(f => setTimeout(f, 1000)); | ||
res = await server | ||
.get(apiPath('search')) | ||
.query({ lastName: 'Aiph7u' }) | ||
expect(res.status).toBe(200); | ||
expect(res.body.response.persons.length).to.above(0); | ||
expect(res.body.response.persons[0].name.first).to.include('Georges'); | ||
}); | ||
|
||
test.sequential('update get all updates (admin)', async () => { | ||
const token = await server | ||
.post(apiPath(`auth`)) | ||
.send({user:process.env.BACKEND_TOKEN_USER, password: process.env.BACKEND_TOKEN_PASSWORD}) | ||
const res = await server | ||
.get(apiPath('updated')) | ||
.set('Authorization', `Bearer ${token.body.access_token as string}`) | ||
expect(res.status).toBe(200); | ||
expect(res.body.length).to.above(0); | ||
}); | ||
|
||
test.sequential('update get author updates', async () => { | ||
const token = await server | ||
.post(apiPath(`auth`)) | ||
.send({user:'[email protected]', password: 'magicPass'}) | ||
const res = await server | ||
.get(apiPath('updated')) | ||
.set('Authorization', `Bearer ${token.body.access_token as string}`) | ||
expect(res.status).toBe(200); | ||
expect(res.body.length).to.above(0); | ||
}); | ||
}) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,8 @@ import { generateRoutes, generateSpec, ExtendedRoutesConfig, ExtendedSpecConfig | |
flow: "password", | ||
tokenUrl: "/deces/api/v1/auth", | ||
scopes: { | ||
admin: "administration access" | ||
admin: "administration access", | ||
user: "user access" | ||
Comment on lines
+19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Remove unused 'admin' scope definition The 'admin' scope is defined in
🔗 Analysis chainLGTM! Verify scope requirements. The addition of the 'user' scope alongside 'admin' enhances access control granularity. This is particularly relevant for managing access to the new updates index. Let's verify the scope usage across the codebase: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for JWT scope usage in controllers and routes
rg -g '*.ts' -A 3 '@Security\(.*\)' ./backend/src/
Length of output: 2969 Script: #!/bin/bash
# Search for any references to admin scope or other security decorators
rg -g '*.ts' -i '(admin.*access|@security|authentication|authorization)' ./backend/src/
Length of output: 6828 |
||
} | ||
}, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Test data inconsistency detected
The lastName value should remain as 'Aiph7u' to maintain consistency with server.spec.ts, as both tests are validating the same functionality with the same author_id ('[email protected]').
backend/src/controllers/search.spec.ts
: Revert lastName from 'Aeboox9e' back to 'Aiph7u'🔗 Analysis chain
Verify test data change rationale.
The modification of the test data from 'Aiph7u' to 'Aeboox9e' seems unrelated to the PR objective.
Let's check if this change is related to any other modifications:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 256
Script:
Length of output: 1295