auto-formatting
This commit is contained in:
@@ -23,18 +23,18 @@ const log = require('../../log')
|
|||||||
|
|
||||||
const eventController = {
|
const eventController = {
|
||||||
|
|
||||||
async searchMeta (req, res) {
|
async searchMeta(req, res) {
|
||||||
const search = req.query.search
|
const search = req.query.search
|
||||||
|
|
||||||
const places = await Place.findAll({
|
const places = await Place.findAll({
|
||||||
order: [[Sequelize.col('w'), 'DESC']],
|
order: [[Sequelize.col('w'), 'DESC']],
|
||||||
where: {
|
where: {
|
||||||
[Op.or]: [
|
[Op.or]: [
|
||||||
Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('name')), 'LIKE', '%' + search + '%' ),
|
Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('name')), 'LIKE', '%' + search + '%'),
|
||||||
Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('address')), 'LIKE', '%' + search + '%')
|
Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('address')), 'LIKE', '%' + search + '%')
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
attributes: [['name', 'label'], 'address', 'id', [Sequelize.cast(Sequelize.fn('COUNT', Sequelize.col('events.placeId')),'INTEGER'), 'w']],
|
attributes: [['name', 'label'], 'address', 'id', [Sequelize.cast(Sequelize.fn('COUNT', Sequelize.col('events.placeId')), 'INTEGER'), 'w']],
|
||||||
include: [{ model: Event, where: { is_visible: true }, required: true, attributes: [] }],
|
include: [{ model: Event, where: { is_visible: true }, required: true, attributes: [] }],
|
||||||
group: ['place.id'],
|
group: ['place.id'],
|
||||||
raw: true
|
raw: true
|
||||||
@@ -44,8 +44,8 @@ const eventController = {
|
|||||||
order: [[Sequelize.col('w'), 'DESC']],
|
order: [[Sequelize.col('w'), 'DESC']],
|
||||||
where: {
|
where: {
|
||||||
tag: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('tag')), 'LIKE', '%' + search + '%'),
|
tag: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('tag')), 'LIKE', '%' + search + '%'),
|
||||||
},
|
},
|
||||||
attributes: [['tag','label'], [Sequelize.cast(Sequelize.fn('COUNT', Sequelize.col('tag.tag')), 'INTEGER'), 'w']],
|
attributes: [['tag', 'label'], [Sequelize.cast(Sequelize.fn('COUNT', Sequelize.col('tag.tag')), 'INTEGER'), 'w']],
|
||||||
include: [{ model: Event, where: { is_visible: true }, attributes: [], through: { attributes: [] }, required: true }],
|
include: [{ model: Event, where: { is_visible: true }, attributes: [], through: { attributes: [] }, required: true }],
|
||||||
group: ['tag.tag'],
|
group: ['tag.tag'],
|
||||||
raw: true
|
raw: true
|
||||||
@@ -57,13 +57,13 @@ const eventController = {
|
|||||||
}).concat(tags.map(t => {
|
}).concat(tags.map(t => {
|
||||||
t.type = 'tag'
|
t.type = 'tag'
|
||||||
return t
|
return t
|
||||||
})).sort( (a, b) => b.w - a.w).slice(0, 10)
|
})).sort((a, b) => b.w - a.w).slice(0, 10)
|
||||||
|
|
||||||
return res.json(ret)
|
return res.json(ret)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
async search (req, res) {
|
async search(req, res) {
|
||||||
const search = req.query.search.trim().toLocaleLowerCase()
|
const search = req.query.search.trim().toLocaleLowerCase()
|
||||||
const show_recurrent = req.query.show_recurrent || false
|
const show_recurrent = req.query.show_recurrent || false
|
||||||
const end = req.query.end
|
const end = req.query.end
|
||||||
@@ -89,11 +89,11 @@ const eventController = {
|
|||||||
if (search) {
|
if (search) {
|
||||||
replacements.push(search)
|
replacements.push(search)
|
||||||
where[Op.or] =
|
where[Op.or] =
|
||||||
[
|
[
|
||||||
{ title: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('title')), 'LIKE', '%' + search + '%') },
|
{ title: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('title')), 'LIKE', '%' + search + '%') },
|
||||||
Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('name')), 'LIKE', '%' + search + '%'),
|
Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('name')), 'LIKE', '%' + search + '%'),
|
||||||
Sequelize.fn('EXISTS', Sequelize.literal(`SELECT 1 FROM event_tags WHERE ${Col('event_tags.eventId')}=${Col('event.id')} AND LOWER(${Col('tagTag')}) = ?`))
|
Sequelize.fn('EXISTS', Sequelize.literal(`SELECT 1 FROM event_tags WHERE ${Col('event_tags.eventId')}=${Col('event.id')} AND LOWER(${Col('tagTag')}) = ?`))
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -129,9 +129,9 @@ const eventController = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async getNotifications (event, action) {
|
async getNotifications(event, action) {
|
||||||
log.debug(`getNotifications ${event.title} ${action}`)
|
log.debug(`getNotifications ${event.title} ${action}`)
|
||||||
function match (event, filters) {
|
function match(event, filters) {
|
||||||
// matches if no filter specified
|
// matches if no filter specified
|
||||||
if (!filters) { return true }
|
if (!filters) { return true }
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ const eventController = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
async get (req, res) {
|
async get(req, res) {
|
||||||
const format = req.params.format || 'json'
|
const format = req.params.format || 'json'
|
||||||
const is_admin = res.locals.user && res.locals.user.is_admin
|
const is_admin = res.locals.user && res.locals.user.is_admin
|
||||||
const slug = req.params.event_slug
|
const slug = req.params.event_slug
|
||||||
@@ -222,7 +222,7 @@ const eventController = {
|
|||||||
recurrent: null,
|
recurrent: null,
|
||||||
[Op.or]: [
|
[Op.or]: [
|
||||||
{ start_datetime: { [Op.gt]: event.start_datetime } },
|
{ start_datetime: { [Op.gt]: event.start_datetime } },
|
||||||
{
|
{
|
||||||
start_datetime: event.start_datetime,
|
start_datetime: event.start_datetime,
|
||||||
id: { [Op.gt]: event.id }
|
id: { [Op.gt]: event.id }
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ const eventController = {
|
|||||||
recurrent: null,
|
recurrent: null,
|
||||||
[Op.or]: [
|
[Op.or]: [
|
||||||
{ start_datetime: { [Op.lt]: event.start_datetime } },
|
{ start_datetime: { [Op.lt]: event.start_datetime } },
|
||||||
{
|
{
|
||||||
start_datetime: event.start_datetime,
|
start_datetime: event.start_datetime,
|
||||||
id: { [Op.lt]: event.id }
|
id: { [Op.lt]: event.id }
|
||||||
}
|
}
|
||||||
@@ -270,7 +270,7 @@ const eventController = {
|
|||||||
/** confirm an anonymous event
|
/** confirm an anonymous event
|
||||||
* and send related notifications
|
* and send related notifications
|
||||||
*/
|
*/
|
||||||
async confirm (req, res) {
|
async confirm(req, res) {
|
||||||
const id = Number(req.params.event_id)
|
const id = Number(req.params.event_id)
|
||||||
const event = await Event.findByPk(id, { include: [Place, Tag] })
|
const event = await Event.findByPk(id, { include: [Place, Tag] })
|
||||||
if (!event) {
|
if (!event) {
|
||||||
@@ -299,7 +299,7 @@ const eventController = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async unconfirm (req, res) {
|
async unconfirm(req, res) {
|
||||||
const id = Number(req.params.event_id)
|
const id = Number(req.params.event_id)
|
||||||
const event = await Event.findByPk(id)
|
const event = await Event.findByPk(id)
|
||||||
if (!event) { return req.sendStatus(404) }
|
if (!event) { return req.sendStatus(404) }
|
||||||
@@ -318,7 +318,7 @@ const eventController = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/** get all unconfirmed events */
|
/** get all unconfirmed events */
|
||||||
async getUnconfirmed (_req, res) {
|
async getUnconfirmed(_req, res) {
|
||||||
try {
|
try {
|
||||||
const events = await Event.findAll({
|
const events = await Event.findAll({
|
||||||
where: {
|
where: {
|
||||||
@@ -336,7 +336,7 @@ const eventController = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async addNotification (req, res) {
|
async addNotification(req, res) {
|
||||||
try {
|
try {
|
||||||
const notification = {
|
const notification = {
|
||||||
filters: { is_visible: true },
|
filters: { is_visible: true },
|
||||||
@@ -351,7 +351,7 @@ const eventController = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async delNotification (req, res) {
|
async delNotification(req, res) {
|
||||||
const remove_code = req.params.code
|
const remove_code = req.params.code
|
||||||
try {
|
try {
|
||||||
const notification = await Notification.findOne({ where: { remove_code } })
|
const notification = await Notification.findOne({ where: { remove_code } })
|
||||||
@@ -362,14 +362,14 @@ const eventController = {
|
|||||||
res.sendStatus(200)
|
res.sendStatus(200)
|
||||||
},
|
},
|
||||||
|
|
||||||
async isAnonEventAllowed (_req, res, next) {
|
async isAnonEventAllowed(_req, res, next) {
|
||||||
if (!res.locals.settings.allow_anon_event && !res.locals.user) {
|
if (!res.locals.settings.allow_anon_event && !res.locals.user) {
|
||||||
return res.sendStatus(403)
|
return res.sendStatus(403)
|
||||||
}
|
}
|
||||||
next()
|
next()
|
||||||
},
|
},
|
||||||
|
|
||||||
async add (req, res) {
|
async add(req, res) {
|
||||||
// req.err comes from multer streaming error
|
// req.err comes from multer streaming error
|
||||||
if (req.err) {
|
if (req.err) {
|
||||||
log.warn(req.err)
|
log.warn(req.err)
|
||||||
@@ -380,7 +380,7 @@ const eventController = {
|
|||||||
const body = req.body
|
const body = req.body
|
||||||
const recurrent = body.recurrent ? JSON.parse(body.recurrent) : null
|
const recurrent = body.recurrent ? JSON.parse(body.recurrent) : null
|
||||||
|
|
||||||
const required_fields = [ 'title', 'start_datetime']
|
const required_fields = ['title', 'start_datetime']
|
||||||
let missing_field = required_fields.find(required_field => !body[required_field])
|
let missing_field = required_fields.find(required_field => !body[required_field])
|
||||||
if (missing_field) {
|
if (missing_field) {
|
||||||
log.warn(`${missing_field} required`)
|
log.warn(`${missing_field} required`)
|
||||||
@@ -398,7 +398,7 @@ const eventController = {
|
|||||||
if (!body.place_name) {
|
if (!body.place_name) {
|
||||||
return res.status(400).send(`Place not found`)
|
return res.status(400).send(`Place not found`)
|
||||||
}
|
}
|
||||||
place = await Place.findOne({ where: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('name')), Op.eq, body.place_name.trim().toLocaleLowerCase() )})
|
place = await Place.findOne({ where: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('name')), Op.eq, body.place_name.trim().toLocaleLowerCase()) })
|
||||||
if (!place) {
|
if (!place) {
|
||||||
if (!body.place_address || !body.place_name) {
|
if (!body.place_address || !body.place_name) {
|
||||||
return res.status(400).send(`place_id or place_name and place_address required`)
|
return res.status(400).send(`place_id or place_name and place_address required`)
|
||||||
@@ -479,7 +479,7 @@ const eventController = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async update (req, res) {
|
async update(req, res) {
|
||||||
if (res.err) {
|
if (res.err) {
|
||||||
log.warn(req.err)
|
log.warn(req.err)
|
||||||
return res.status(400).json(req.err.toString())
|
return res.status(400).json(req.err.toString())
|
||||||
@@ -537,7 +537,7 @@ const eventController = {
|
|||||||
} else if (body.image_focalpoint && event.media.length) {
|
} else if (body.image_focalpoint && event.media.length) {
|
||||||
let focalpoint = body.image_focalpoint ? body.image_focalpoint.split(',') : ['0', '0']
|
let focalpoint = body.image_focalpoint ? body.image_focalpoint.split(',') : ['0', '0']
|
||||||
focalpoint = [parseFloat(parseFloat(focalpoint[0]).toFixed(2)), parseFloat(parseFloat(focalpoint[1]).toFixed(2))]
|
focalpoint = [parseFloat(parseFloat(focalpoint[0]).toFixed(2)), parseFloat(parseFloat(focalpoint[1]).toFixed(2))]
|
||||||
eventDetails.media = [ { ...event.media[0], focalpoint } ] // [0].focalpoint = focalpoint
|
eventDetails.media = [{ ...event.media[0], focalpoint }] // [0].focalpoint = focalpoint
|
||||||
}
|
}
|
||||||
await event.update(eventDetails)
|
await event.update(eventDetails)
|
||||||
|
|
||||||
@@ -552,7 +552,7 @@ const eventController = {
|
|||||||
if (!body.place_name) {
|
if (!body.place_name) {
|
||||||
return res.status(400).send(`Place not found`)
|
return res.status(400).send(`Place not found`)
|
||||||
}
|
}
|
||||||
place = await Place.findOne({ where: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('name')), Op.eq, body.place_name.trim().toLocaleLowerCase() )})
|
place = await Place.findOne({ where: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('name')), Op.eq, body.place_name.trim().toLocaleLowerCase()) })
|
||||||
if (!place) {
|
if (!place) {
|
||||||
if (!body.place_address || !body.place_name) {
|
if (!body.place_address || !body.place_name) {
|
||||||
return res.status(400).send(`place_id or place_name and place_address required`)
|
return res.status(400).send(`place_id or place_name and place_address required`)
|
||||||
@@ -565,7 +565,7 @@ const eventController = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await event.setPlace(place)
|
await event.setPlace(place)
|
||||||
|
|
||||||
// create/assign tags
|
// create/assign tags
|
||||||
let tags = []
|
let tags = []
|
||||||
if (body.tags) {
|
if (body.tags) {
|
||||||
@@ -593,7 +593,7 @@ const eventController = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async remove (req, res) {
|
async remove(req, res) {
|
||||||
const event = await Event.findByPk(req.params.id)
|
const event = await Event.findByPk(req.params.id)
|
||||||
// check if event is mine (or user is admin)
|
// check if event is mine (or user is admin)
|
||||||
if (event && (res.locals.user.is_admin || res.locals.user.id === event.userId)) {
|
if (event && (res.locals.user.is_admin || res.locals.user.id === event.userId)) {
|
||||||
@@ -626,7 +626,7 @@ const eventController = {
|
|||||||
* Method to search for events with pagination and filtering
|
* Method to search for events with pagination and filtering
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async _select ({
|
async _select({
|
||||||
start = dayjs().unix(),
|
start = dayjs().unix(),
|
||||||
end,
|
end,
|
||||||
tags,
|
tags,
|
||||||
@@ -665,8 +665,8 @@ const eventController = {
|
|||||||
|
|
||||||
const replacements = []
|
const replacements = []
|
||||||
if (tags && places) {
|
if (tags && places) {
|
||||||
where[Op.and] = [
|
where[Op.and] = [
|
||||||
{ placeId: places ? places.split(',') : []},
|
{ placeId: places ? places.split(',') : [] },
|
||||||
Sequelize.fn('EXISTS', Sequelize.literal(`SELECT 1 FROM event_tags WHERE ${Col('event_tags.eventId')}=${Col('event.id')} AND LOWER(${Col('tagTag')}) in (?)`))
|
Sequelize.fn('EXISTS', Sequelize.literal(`SELECT 1 FROM event_tags WHERE ${Col('event_tags.eventId')}=${Col('event.id')} AND LOWER(${Col('tagTag')}) in (?)`))
|
||||||
]
|
]
|
||||||
replacements.push(tags)
|
replacements.push(tags)
|
||||||
@@ -679,10 +679,10 @@ const eventController = {
|
|||||||
|
|
||||||
let pagination = {}
|
let pagination = {}
|
||||||
if (limit) {
|
if (limit) {
|
||||||
pagination = {
|
pagination = {
|
||||||
limit,
|
limit,
|
||||||
offset: limit * page,
|
offset: limit * page,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const events = await Event.findAll({
|
const events = await Event.findAll({
|
||||||
@@ -690,7 +690,7 @@ const eventController = {
|
|||||||
attributes: {
|
attributes: {
|
||||||
exclude: ['likes', 'boost', 'userId', 'is_visible', 'createdAt', 'description', 'resources', 'recurrent', 'placeId', 'image_path']
|
exclude: ['likes', 'boost', 'userId', 'is_visible', 'createdAt', 'description', 'resources', 'recurrent', 'placeId', 'image_path']
|
||||||
},
|
},
|
||||||
order: [['start_datetime', older ? 'DESC' : 'ASC' ]],
|
order: [['start_datetime', older ? 'DESC' : 'ASC']],
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Tag,
|
model: Tag,
|
||||||
@@ -717,7 +717,7 @@ const eventController = {
|
|||||||
/**
|
/**
|
||||||
* Select events based on params
|
* Select events based on params
|
||||||
*/
|
*/
|
||||||
async select (req, res) {
|
async select(req, res) {
|
||||||
const settings = res.locals.settings
|
const settings = res.locals.settings
|
||||||
const start = req.query.start || dayjs().unix()
|
const start = req.query.start || dayjs().unix()
|
||||||
const end = req.query.end
|
const end = req.query.end
|
||||||
@@ -738,7 +738,7 @@ const eventController = {
|
|||||||
/**
|
/**
|
||||||
* Ensure we have the next instance of a recurrent event
|
* Ensure we have the next instance of a recurrent event
|
||||||
*/
|
*/
|
||||||
async _createRecurrentOccurrence (e, startAt) {
|
async _createRecurrentOccurrence(e, startAt) {
|
||||||
log.debug(`Create recurrent event [${e.id}] ${e.title}"`)
|
log.debug(`Create recurrent event [${e.id}] ${e.title}"`)
|
||||||
const event = {
|
const event = {
|
||||||
parentId: e.id,
|
parentId: e.id,
|
||||||
@@ -798,12 +798,12 @@ const eventController = {
|
|||||||
/**
|
/**
|
||||||
* Create instances of recurrent events
|
* Create instances of recurrent events
|
||||||
*/
|
*/
|
||||||
async _createRecurrent (start_datetime = dayjs().unix()) {
|
async _createRecurrent(start_datetime = dayjs().unix()) {
|
||||||
// select recurrent events and its childs
|
// select recurrent events and its childs
|
||||||
const events = await Event.findAll({
|
const events = await Event.findAll({
|
||||||
where: { is_visible: true, recurrent: { [Op.ne]: null } },
|
where: { is_visible: true, recurrent: { [Op.ne]: null } },
|
||||||
include: [{ model: Tag, required: false },
|
include: [{ model: Tag, required: false },
|
||||||
{ model: Event, as: 'child', required: false, where: { start_datetime: { [Op.gte]: start_datetime } }}],
|
{ model: Event, as: 'child', required: false, where: { start_datetime: { [Op.gte]: start_datetime } } }],
|
||||||
order: [['child', 'start_datetime', 'DESC']]
|
order: [['child', 'start_datetime', 'DESC']]
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -811,7 +811,7 @@ const eventController = {
|
|||||||
const creations = events.map(e => {
|
const creations = events.map(e => {
|
||||||
if (e.child.length) {
|
if (e.child.length) {
|
||||||
if (e.child.find(c => c.is_visible)) return
|
if (e.child.find(c => c.is_visible)) return
|
||||||
return eventController._createRecurrentOccurrence(e, dayjs.unix(e.child[0].start_datetime+1))
|
return eventController._createRecurrentOccurrence(e, dayjs.unix(e.child[0].start_datetime + 1))
|
||||||
}
|
}
|
||||||
return eventController._createRecurrentOccurrence(e, dayjs())
|
return eventController._createRecurrentOccurrence(e, dayjs())
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ let token
|
|||||||
let app
|
let app
|
||||||
let places = []
|
let places = []
|
||||||
|
|
||||||
beforeAll( async () => {
|
beforeAll(async () => {
|
||||||
switch (process.env.DB) {
|
switch (process.env.DB) {
|
||||||
case 'mariadb':
|
case 'mariadb':
|
||||||
process.env.config_path = path.resolve(__dirname, './seeds/config.mariadb.json')
|
process.env.config_path = path.resolve(__dirname, './seeds/config.mariadb.json')
|
||||||
@@ -32,7 +32,7 @@ beforeAll( async () => {
|
|||||||
await sequelize.query('DELETE FROM filters')
|
await sequelize.query('DELETE FROM filters')
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll( async () => {
|
afterAll(async () => {
|
||||||
await require('../server/initialize.server.js').shutdown(false)
|
await require('../server/initialize.server.js').shutdown(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ describe('Authentication / Authorization', () => {
|
|||||||
expect(response.body.token_type).toBe('Bearer')
|
expect(response.body.token_type).toBe('Bearer')
|
||||||
token = response.body
|
token = response.body
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should get user when authenticated', async () => {
|
test('should get user when authenticated', async () => {
|
||||||
const response = await request(app).get('/api/user')
|
const response = await request(app).get('/api/user')
|
||||||
.auth(token.access_token, { type: 'bearer' })
|
.auth(token.access_token, { type: 'bearer' })
|
||||||
@@ -105,16 +105,16 @@ describe('Settings', () => {
|
|||||||
test('should retrieve stored array settings', async () => {
|
test('should retrieve stored array settings', async () => {
|
||||||
await request(app).post('/api/settings')
|
await request(app).post('/api/settings')
|
||||||
.auth(token.access_token, { type: 'bearer' })
|
.auth(token.access_token, { type: 'bearer' })
|
||||||
.send({ key: 'test', value: [1,2,'test'] })
|
.send({ key: 'test', value: [1, 2, 'test'] })
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.get('/api/settings')
|
.get('/api/settings')
|
||||||
.auth(token.access_token, { type: 'bearer' })
|
.auth(token.access_token, { type: 'bearer' })
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(response.body.test.length).toBe(3)
|
expect(response.body.test.length).toBe(3)
|
||||||
expect(response.body.test).toStrictEqual([1,2,'test'])
|
expect(response.body.test).toStrictEqual([1, 2, 'test'])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ describe('Settings', () => {
|
|||||||
.get('/api/settings')
|
.get('/api/settings')
|
||||||
.auth(token.access_token, { type: 'bearer' })
|
.auth(token.access_token, { type: 'bearer' })
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(response.body.test.name).toBe('test object')
|
expect(response.body.test.name).toBe('test object')
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -143,9 +143,9 @@ describe('Settings', () => {
|
|||||||
.get('/api/settings')
|
.get('/api/settings')
|
||||||
.auth(token.access_token, { type: 'bearer' })
|
.auth(token.access_token, { type: 'bearer' })
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(response.body.test).toBe('test string')
|
expect(response.body.test).toBe('test string')
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ describe('Events', () => {
|
|||||||
const required_fields = {
|
const required_fields = {
|
||||||
'title': {},
|
'title': {},
|
||||||
'start_datetime': { title: 'test title' },
|
'start_datetime': { title: 'test title' },
|
||||||
'place_id or place_name and place_address': { title: 'test title', start_datetime: dayjs().unix()+1000, place_name: 'test place name'},
|
'place_id or place_name and place_address': { title: 'test title', start_datetime: dayjs().unix() + 1000, place_name: 'test place name' },
|
||||||
}
|
}
|
||||||
|
|
||||||
const promises = Object.keys(required_fields).map(async field => {
|
const promises = Object.keys(required_fields).map(async field => {
|
||||||
@@ -171,15 +171,15 @@ describe('Events', () => {
|
|||||||
test('should create anon event only when allowed', async () => {
|
test('should create anon event only when allowed', async () => {
|
||||||
|
|
||||||
await request(app).post('/api/settings')
|
await request(app).post('/api/settings')
|
||||||
.send({ key: 'allow_anon_event', value: false })
|
.send({ key: 'allow_anon_event', value: false })
|
||||||
.auth(token.access_token, { type: 'bearer' })
|
.auth(token.access_token, { type: 'bearer' })
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
await request(app).post('/api/event')
|
await request(app).post('/api/event')
|
||||||
.expect(403)
|
.expect(403)
|
||||||
|
|
||||||
let response = await request(app).post('/api/event')
|
let response = await request(app).post('/api/event')
|
||||||
.send({ title: 'test title 2', place_name: 'place name', place_address: 'address', tags: ['test'], start_datetime: dayjs().unix()+1000 })
|
.send({ title: 'test title 2', place_name: 'place name', place_address: 'address', tags: ['test'], start_datetime: dayjs().unix() + 1000 })
|
||||||
.auth(token.access_token, { type: 'bearer' })
|
.auth(token.access_token, { type: 'bearer' })
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
@@ -189,10 +189,10 @@ describe('Events', () => {
|
|||||||
await request(app).post('/api/settings')
|
await request(app).post('/api/settings')
|
||||||
.send({ key: 'allow_anon_event', value: true })
|
.send({ key: 'allow_anon_event', value: true })
|
||||||
.auth(token.access_token, { type: 'bearer' })
|
.auth(token.access_token, { type: 'bearer' })
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
response = await request(app).post('/api/event')
|
response = await request(app).post('/api/event')
|
||||||
.send({ title: 'test title 3', place_name: 'place name 2', place_address: 'address 2', tags: ['test'], start_datetime: dayjs().unix()+1000 })
|
.send({ title: 'test title 3', place_name: 'place name 2', place_address: 'address 2', tags: ['test'], start_datetime: dayjs().unix() + 1000 })
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(response.body.place.id).toBeDefined()
|
expect(response.body.place.id).toBeDefined()
|
||||||
@@ -204,7 +204,7 @@ describe('Events', () => {
|
|||||||
const event = {
|
const event = {
|
||||||
title: 'test title 4',
|
title: 'test title 4',
|
||||||
place_id: places[0],
|
place_id: places[0],
|
||||||
start_datetime: dayjs().unix()+1000,
|
start_datetime: dayjs().unix() + 1000,
|
||||||
tags: [' test tag ']
|
tags: [' test tag ']
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ let event = {}
|
|||||||
describe('Tags', () => {
|
describe('Tags', () => {
|
||||||
test('should create event with tags', async () => {
|
test('should create event with tags', async () => {
|
||||||
event = await request(app).post('/api/event')
|
event = await request(app).post('/api/event')
|
||||||
.send({ title: 'test tags', place_id: places[1], start_datetime: dayjs().unix()+1000 , tags: ['tag1', 'Tag2', 'tAg3'] })
|
.send({ title: 'test tags', place_id: places[1], start_datetime: dayjs().unix() + 1000, tags: ['tag1', 'Tag2', 'tAg3'] })
|
||||||
.auth(token.access_token, { type: 'bearer' })
|
.auth(token.access_token, { type: 'bearer' })
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
@@ -231,7 +231,7 @@ describe('Tags', () => {
|
|||||||
|
|
||||||
test('should create event trimming tags / ignore sensitiviness', async () => {
|
test('should create event trimming tags / ignore sensitiviness', async () => {
|
||||||
const ret = await request(app).post('/api/event')
|
const ret = await request(app).post('/api/event')
|
||||||
.send({ title: 'test trimming tags', place_id: places[1], start_datetime: dayjs().unix()+1000, tags: ['Tag1', 'taG2 '] })
|
.send({ title: 'test trimming tags', place_id: places[1], start_datetime: dayjs().unix() + 1000, tags: ['Tag1', 'taG2 '] })
|
||||||
.auth(token.access_token, { type: 'bearer' })
|
.auth(token.access_token, { type: 'bearer' })
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
@@ -243,9 +243,9 @@ describe('Tags', () => {
|
|||||||
|
|
||||||
test('should modify event tags', async () => {
|
test('should modify event tags', async () => {
|
||||||
const ret = await request(app).put('/api/event')
|
const ret = await request(app).put('/api/event')
|
||||||
.send({ id: event.body.id, tags: ['tag1', 'tag3', 'tag4'], place_id: places[1] })
|
.send({ id: event.body.id, tags: ['tag1', 'tag3', 'tag4'], place_id: places[1] })
|
||||||
.auth(token.access_token, { type: 'bearer' })
|
.auth(token.access_token, { type: 'bearer' })
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(ret.body.tags).toStrictEqual(['tag1', 'tAg3', 'tag4'])
|
expect(ret.body.tags).toStrictEqual(['tag1', 'tAg3', 'tag4'])
|
||||||
})
|
})
|
||||||
@@ -253,7 +253,7 @@ describe('Tags', () => {
|
|||||||
test('should return events searching for tags', async () => {
|
test('should return events searching for tags', async () => {
|
||||||
const response = await request(app).get('/api/events?tags=tAg3')
|
const response = await request(app).get('/api/events?tags=tAg3')
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(response.body.length).toBe(1)
|
expect(response.body.length).toBe(1)
|
||||||
// expect(response.body[0].title).toBe('test tags')
|
// expect(response.body[0].title).toBe('test tags')
|
||||||
expect(response.body[0].tags.length).toBe(3)
|
expect(response.body[0].tags.length).toBe(3)
|
||||||
@@ -264,7 +264,7 @@ describe('Place', () => {
|
|||||||
test('should get events by place', async () => {
|
test('should get events by place', async () => {
|
||||||
const response = await request(app).get('/api/place/place name 2')
|
const response = await request(app).get('/api/place/place name 2')
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(response.body.place.name).toBe('place name 2')
|
expect(response.body.place.name).toBe('place name 2')
|
||||||
expect(response.body.events.length).toBe(2)
|
expect(response.body.events.length).toBe(2)
|
||||||
expect(response.body.events[0].place.name).toBe('place name 2')
|
expect(response.body.events[0].place.name).toBe('place name 2')
|
||||||
@@ -277,7 +277,7 @@ describe('Place', () => {
|
|||||||
const response = await request(app).get('/api/place/all')
|
const response = await request(app).get('/api/place/all')
|
||||||
.auth(token.access_token, { type: 'bearer' })
|
.auth(token.access_token, { type: 'bearer' })
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
|
|
||||||
expect(response.body.length).toBe(2)
|
expect(response.body.length).toBe(2)
|
||||||
})
|
})
|
||||||
@@ -285,7 +285,7 @@ describe('Place', () => {
|
|||||||
test('should search for a place', async () => {
|
test('should search for a place', async () => {
|
||||||
const response = await request(app).get('/api/place?search=place')
|
const response = await request(app).get('/api/place?search=place')
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(response.body.length).toBe(2)
|
expect(response.body.length).toBe(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -293,7 +293,7 @@ describe('Place', () => {
|
|||||||
|
|
||||||
let collections = []
|
let collections = []
|
||||||
let filters = []
|
let filters = []
|
||||||
describe ('Collection', () => {
|
describe('Collection', () => {
|
||||||
test('should not create a new collection if not allowed', () => {
|
test('should not create a new collection if not allowed', () => {
|
||||||
return request(app).post('/api/collections')
|
return request(app).post('/api/collections')
|
||||||
.send({ name: 'test collection' })
|
.send({ name: 'test collection' })
|
||||||
@@ -313,8 +313,8 @@ describe ('Collection', () => {
|
|||||||
const response = await request(app).get('/api/collections/test collection')
|
const response = await request(app).get('/api/collections/test collection')
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(response.body.length).toBe(0)
|
expect(response.body.length).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should add a new filter', async () => {
|
test('should add a new filter', async () => {
|
||||||
await request(app)
|
await request(app)
|
||||||
@@ -384,7 +384,7 @@ describe ('Collection', () => {
|
|||||||
// .expect(200)
|
// .expect(200)
|
||||||
// expect(response.body.length).toBe(1)
|
// expect(response.body.length).toBe(1)
|
||||||
|
|
||||||
response = await request(app)
|
response = await request(app)
|
||||||
.get(`/api/collections/test collection`)
|
.get(`/api/collections/test collection`)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user