mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
more test
This commit is contained in:
parent
9a1f650a3b
commit
2fa24b9478
6 changed files with 61 additions and 18 deletions
9
.gitignore
vendored
9
.gitignore
vendored
|
@ -1,13 +1,14 @@
|
|||
# Created by .ignore support plugin (hsz.mobi)
|
||||
|
||||
### Gancio dev configuration
|
||||
*.sqlite
|
||||
gancio.sqlite
|
||||
db.sqlite
|
||||
releases
|
||||
wp-plugin/wpgancio
|
||||
config/development.json
|
||||
gancio_config.json
|
||||
config.json
|
||||
db.sqlite
|
||||
/gancio_config.json
|
||||
/config.json
|
||||
/assets/config.json
|
||||
thumb
|
||||
docs/_site
|
||||
.vscode
|
||||
|
|
|
@ -290,6 +290,13 @@ const eventController = {
|
|||
res.sendStatus(200)
|
||||
},
|
||||
|
||||
async isAnonEventAllowed (req, res, next) {
|
||||
if (!res.locals.settings.allow_anon_event) {
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
next()
|
||||
},
|
||||
|
||||
async add (req, res) {
|
||||
// req.err comes from multer streaming error
|
||||
if (req.err) {
|
||||
|
|
|
@ -101,7 +101,7 @@ if (config.status !== 'READY') {
|
|||
*/
|
||||
|
||||
// allow anyone to add an event (anon event has to be confirmed, TODO: flood protection)
|
||||
api.post('/event', upload.single('image'), eventController.add)
|
||||
api.post('/event', eventController.isAnonEventAllowed, upload.single('image'), eventController.add)
|
||||
|
||||
api.put('/event', isAuth, upload.single('image'), eventController.update)
|
||||
api.get('/event/import', isAuth, helpers.importURL)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const request = require('supertest')
|
||||
const fs = require('fs')
|
||||
|
||||
const admin = { username: 'admin', password: 'SsJOn5l0JpBE', grant_type: 'password', client_id: 'self' }
|
||||
const admin = { username: 'admin', password: 'JqFuXEnkTyOR', grant_type: 'password', client_id: 'self' }
|
||||
let token
|
||||
// - event list should be empty
|
||||
// - try to write without auth
|
||||
|
@ -11,6 +12,7 @@ let token
|
|||
// - should login with correct authentication
|
||||
let app
|
||||
beforeAll( async () => {
|
||||
fs.copyFileSync('./starter.sqlite', './testdb.sqlite')
|
||||
await require('../server/initialize.server.js')()
|
||||
app = require('../server/routes.js')
|
||||
})
|
||||
|
@ -61,17 +63,29 @@ describe('Authentication / Authorization', () => {
|
|||
.expect(403)
|
||||
})
|
||||
|
||||
// test('should create anon event only when allowed', async () => {
|
||||
// let response
|
||||
// response = await request(app)
|
||||
// .post('/api/settings') // auth._token.local
|
||||
// .send({ key: 'allow_anon_event', value: false })
|
||||
// .auth(token.access_token, { type: 'bearer' })
|
||||
// .expect(200)
|
||||
// // expect(response.statusCode).toBe(200)
|
||||
// // response = await request(app).post('/api/settings')
|
||||
// // .send({ key: 'allow_anon_event', value: false })
|
||||
// })
|
||||
test('should create anon event only when allowed', async () => {
|
||||
let response
|
||||
response = await request(app).post('/api/settings')
|
||||
.send({ key: 'allow_anon_event', value: false })
|
||||
.auth(token.access_token, { type: 'bearer' })
|
||||
.expect(200)
|
||||
|
||||
response = await request(app).post('/api/event')
|
||||
.expect(403)
|
||||
|
||||
response = await request(app).post('/api/settings')
|
||||
.send({ key: 'allow_anon_event', value: true })
|
||||
.auth(token.access_token, { type: 'bearer' })
|
||||
.expect(200)
|
||||
|
||||
response = await request(app).post('/api/event')
|
||||
.send({ title: 'test title', place_name: 'place name', start_datetime: new Date().getTime() * 1000 })
|
||||
.expect(200)
|
||||
|
||||
// expect(response.statusCode).toBe(200)
|
||||
// response = await request(app).post('/api/settings')
|
||||
// .send({ key: 'allow_anon_event', value: false })
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
@ -87,7 +101,7 @@ describe('Events', () => {
|
|||
|
||||
const promises = Object.keys(required_fields).map(async field => {
|
||||
const response = await request(app).post('/api/event').send(required_fields[field])
|
||||
expect(response.statusCode).toBe(400)
|
||||
.expect(400)
|
||||
expect(response.text).toBe(`${field} is required`)
|
||||
return
|
||||
})
|
||||
|
|
21
tests/seeds/config.json
Normal file
21
tests/seeds/config.json
Normal file
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"baseurl": "http://localhost:13120",
|
||||
"hostname": "127.0.0.1",
|
||||
"server": {
|
||||
"host": "0.0.0.0",
|
||||
"port": 13120
|
||||
},
|
||||
"log_level": "error",
|
||||
"log_path": "./logs",
|
||||
"db": {
|
||||
"dialect": "sqlite",
|
||||
"storage": "./testdb.sqlite",
|
||||
"host": "localhost",
|
||||
"database": "gancio",
|
||||
"logging": false,
|
||||
"dialectOptions": {
|
||||
"autoJsonMap": false
|
||||
}
|
||||
},
|
||||
"upload_path": "./uploads"
|
||||
}
|
BIN
tests/seeds/starter.sqlite
Normal file
BIN
tests/seeds/starter.sqlite
Normal file
Binary file not shown.
Loading…
Reference in a new issue