Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #177 from AntoineDao/tests
Browse files Browse the repository at this point in the history
Stream and Object tests
  • Loading branch information
didimitrie authored Jan 17, 2020
2 parents c53ad37 + abdcc7d commit 380b676
Show file tree
Hide file tree
Showing 6 changed files with 1,534 additions and 13 deletions.
23 changes: 14 additions & 9 deletions app/api/objects/ObjectDerive.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { merge } = require( 'lodash' )

const SpeckleObject = require( '../../../models/SpeckleObject' )
const BulkObjectSave = require( '../middleware/BulkObjectSave' )
const PermissionCheck = require( '../middleware/PermissionCheck' )

// Derives an object from an existing object
module.exports = ( req, res ) => {
Expand All @@ -14,21 +15,25 @@ module.exports = ( req, res ) => {
let objects = req.body

SpeckleObject.find( { _id: { $in: objects.map( obj => obj._id ) } } ).lean()
.then( objects => Promise.all( objects.map( o => PermissionCheck( req.user, 'read', o ) ).map( prom => prom.catch( e => e ) ) ) )
.then( existingObjects => {
let toSave = [ ]

for ( let original of existingObjects ) {
let found = objects.find( o => o._id === original._id.toString() )
let mod = {}
if ( original._id ) {
let found = objects.find( o => o._id === original._id.toString() )
let mod = {}

merge( mod, original, found )
merge( mod, original, found )

// delete hash to prepare for rehashing in bulk save
delete mod.hash
delete mod._id
delete mod.createdAt
toSave.push( mod )
// delete hash to prepare for rehashing in bulk save
delete mod.hash
delete mod._id
delete mod.createdAt
toSave.push( mod )
}
}
return BulkObjectSave( toSave, req.user )
return BulkObjectSave( toSave, req.user );
} )
.then( newObjects => {
res.send( { success: true, message: 'Saved objects to database.', resources: newObjects.map( o => { return { type: 'Placeholder', _id: o._id } } ) } )
Expand Down
3 changes: 1 addition & 2 deletions app/api/streams/StreamDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ module.exports = ( req, res ) => {
.then( stream => PermissionCheck( req.user, 'delete', stream ) )
.then( stream => {
myStream = stream
DataStream.remove( { streamId: { $in: [ ...myStream.children, req.params.streamId ] } } )
return stream.remove( )
return DataStream.deleteMany( { streamId: { $in: [ ...myStream.children, req.params.streamId ] } } )
} )
.then( ( ) => {
return res.send( { success: true, message: `Stream ${req.params.streamId} and its children have been deleted.`, deletedStreams: [ ...myStream.children, req.params.streamId ] } )
Expand Down
3 changes: 2 additions & 1 deletion app/api/streams/StreamGetAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module.exports = ( req, res ) => {
finalCriteria.$or = [
{ owner: req.user._id },
{ 'canWrite': mongoose.Types.ObjectId( req.user._id ) },
{ 'canRead': mongoose.Types.ObjectId( req.user._id ) }
{ 'canRead': mongoose.Types.ObjectId( req.user._id ) },
{ 'private': false }
]

DataStream.find( finalCriteria, query.options.fields, { sort: query.options.sort, skip: query.options.skip, limit: query.options.limit } )
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js",
"lint": "eslint .",
"lint": "eslint . --fix",
"test": "NODE_ENV=test mocha --timeout 120000 --exit --recursive"
},
"author": "Dimitrie Stefanescu & Project Contributors",
Expand Down
Loading

0 comments on commit 380b676

Please sign in to comment.