add file resources for apib tests and env dependent tmp file usage for tests
parent
eda2389eda
commit
29c53c03a5
|
@ -47,7 +47,8 @@ Thumbs.db
|
||||||
# Internal Data
|
# Internal Data
|
||||||
public/
|
public/
|
||||||
mongodb-data/
|
mongodb-data/
|
||||||
resource/
|
api/resource/
|
||||||
|
api/apib/dredd/data/tmp-resource
|
||||||
backup/
|
backup/
|
||||||
|
|
||||||
# System
|
# System
|
||||||
|
|
|
@ -45,15 +45,12 @@ Create a new squad
|
||||||
|
|
||||||
BLUFOR
|
BLUFOR
|
||||||
-----BOUNDARY
|
-----BOUNDARY
|
||||||
Content-Disposition: form-data; name="image"; filename="image.jpg"
|
Content-Disposition: form-data; name="image"; filename="image.png"
|
||||||
Content-Type: image/jpeg
|
Content-Type: image/png
|
||||||
Content-Transfer-Encoding: base64
|
Content-Transfer-Encoding: base64
|
||||||
|
|
||||||
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
|
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlMA
|
||||||
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy
|
QObYZgAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=
|
||||||
MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAABAAEDASIA
|
|
||||||
AhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEB
|
|
||||||
AAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AL+AD//Z
|
|
||||||
-----BOUNDARY--
|
-----BOUNDARY--
|
||||||
|
|
||||||
+ Response 201
|
+ Response 201
|
||||||
|
@ -80,15 +77,12 @@ Update squad, identified by its id
|
||||||
|
|
||||||
OPFOR
|
OPFOR
|
||||||
-----BOUNDARY
|
-----BOUNDARY
|
||||||
Content-Disposition: form-data; name="image"; filename="image.jpg"
|
Content-Disposition: form-data; name="image"; filename="image.png"
|
||||||
Content-Type: image/jpeg
|
Content-Type: image/png
|
||||||
Content-Transfer-Encoding: base64
|
Content-Transfer-Encoding: base64
|
||||||
|
|
||||||
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
|
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlMA
|
||||||
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy
|
QObYZgAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=
|
||||||
MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAABAAEDASIA
|
|
||||||
AhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEB
|
|
||||||
AAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AL+AD//Z
|
|
||||||
-----BOUNDARY--
|
-----BOUNDARY--
|
||||||
|
|
||||||
+ Response 200
|
+ Response 200
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 95 B |
Binary file not shown.
After Width: | Height: | Size: 95 B |
Binary file not shown.
After Width: | Height: | Size: 95 B |
|
@ -1,5 +1,6 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
port: 8091,
|
port: 8091,
|
||||||
|
resourceLocation: __dirname + '/../resource',
|
||||||
|
|
||||||
database: {
|
database: {
|
||||||
uri: 'mongodb://localhost:27017/',
|
uri: 'mongodb://localhost:27017/',
|
||||||
|
@ -19,10 +20,11 @@ module.exports = {
|
||||||
dredd: {
|
dredd: {
|
||||||
env: 'dreddTest',
|
env: 'dreddTest',
|
||||||
port: 3001,
|
port: 3001,
|
||||||
|
resourceLocation: __dirname + '/../apib/dredd/data/tmp-resource',
|
||||||
},
|
},
|
||||||
unit: {
|
unit: {
|
||||||
env: 'unitTest',
|
env: 'unitTest',
|
||||||
port: 3010,
|
port: 3002,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const config = require('../config/config');
|
||||||
|
|
||||||
|
const resourceLocation = () => {
|
||||||
|
if (process.env.NODE_ENV === config.test.dredd.env) {
|
||||||
|
return config.test.dredd.resourceLocation
|
||||||
|
}
|
||||||
|
return config.resourceLocation;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.resourceLocation = resourceLocation;
|
|
@ -12,7 +12,7 @@
|
||||||
"lint": "eslint '**/*.js'",
|
"lint": "eslint '**/*.js'",
|
||||||
"test": "mocha --require ./test/config/spec_helper.js",
|
"test": "mocha --require ./test/config/spec_helper.js",
|
||||||
"start-test": "DEBUG='cc:*' NODE_ENV=unitTest node server.js",
|
"start-test": "DEBUG='cc:*' NODE_ENV=unitTest node server.js",
|
||||||
"start-api-test": "DEBUG='cc:*' NODE_ENV=dreddTest node server.js",
|
"start-api-test": "rm -rf ./apib/dredd/data/tmp-resource && cp -r ./apib/dredd/data/resource ./apib/dredd/data/tmp-resource && DEBUG='cc:*' NODE_ENV=dreddTest node server.js",
|
||||||
"api:compile-docs": "$(npm bin)/hercule apib/dev-doc.apib -o apib/documentation.apib",
|
"api:compile-docs": "$(npm bin)/hercule apib/dev-doc.apib -o apib/documentation.apib",
|
||||||
"api:publish-docs": "$(npm bin)/aglio --theme-variables slate -i ./apib/documentation.apib -o ../public/api-docs.html",
|
"api:publish-docs": "$(npm bin)/aglio --theme-variables slate -i ./apib/documentation.apib -o ../public/api-docs.html",
|
||||||
"api:test-docs": "npm run api:docs && ./apib/dredd/populate-data.sh && $(npm bin)/dredd",
|
"api:test-docs": "npm run api:docs && ./apib/dredd/populate-data.sh && $(npm bin)/dredd",
|
||||||
|
|
|
@ -15,6 +15,7 @@ const checkHl = require('../middleware/permission-check').checkHl;
|
||||||
|
|
||||||
const routerHandling = require('../middleware/router-handling');
|
const routerHandling = require('../middleware/router-handling');
|
||||||
const idValidator = require('../middleware/validators').idValidator;
|
const idValidator = require('../middleware/validators').idValidator;
|
||||||
|
const resourceLocation = require('../middleware/resource-location').resourceLocation().concat('/decoration/');
|
||||||
|
|
||||||
// Mongoose Model using mongoDB
|
// Mongoose Model using mongoDB
|
||||||
const DecorationModel = require('../models/decoration');
|
const DecorationModel = require('../models/decoration');
|
||||||
|
@ -65,7 +66,7 @@ decoration.route('/')
|
||||||
}
|
}
|
||||||
res.status(codes.created);
|
res.status(codes.created);
|
||||||
res.locals.items = decoration;
|
res.locals.items = decoration;
|
||||||
fs.appendFile(__dirname + '/../resource/decoration/' + decoration.id + '.png',
|
fs.appendFile(resourceLocation + decoration._id + '.png',
|
||||||
new Buffer(req.file.buffer),
|
new Buffer(req.file.buffer),
|
||||||
(err) => {
|
(err) => {
|
||||||
if (err) next(err);
|
if (err) next(err);
|
||||||
|
@ -109,7 +110,7 @@ decoration.route('/:id')
|
||||||
req.body.$inc = {__v: 1};
|
req.body.$inc = {__v: 1};
|
||||||
|
|
||||||
if (req.file) {
|
if (req.file) {
|
||||||
const file = __dirname + '/../resource/decoration/' + req.body._id + '.png';
|
const file = resourceLocation + req.body._id + '.png';
|
||||||
fs.unlink(file, (err) => {
|
fs.unlink(file, (err) => {
|
||||||
if (err) next(err);
|
if (err) next(err);
|
||||||
fs.appendFile(file, new Buffer(req.file.buffer), (err) => {
|
fs.appendFile(file, new Buffer(req.file.buffer), (err) => {
|
||||||
|
@ -146,15 +147,12 @@ decoration.route('/:id')
|
||||||
AwardingsModel.find({decorationId: req.params.id}).remove().exec();
|
AwardingsModel.find({decorationId: req.params.id}).remove().exec();
|
||||||
|
|
||||||
// delete graphic
|
// delete graphic
|
||||||
fs.unlink(__dirname + '/../resource/decoration/' + req.params.id + '.png',
|
fs.unlink(resourceLocation + req.params.id + '.png',
|
||||||
(err) => {
|
(err) => {
|
||||||
if (err) next(err);
|
// we don't set res.locals.items and thus it will send a 204 (no content) at the end. see last handler
|
||||||
|
res.locals.processed = true;
|
||||||
|
next(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
// we don't set res.locals.items and thus it will send a 204 (no content) at the end. see last handler
|
|
||||||
// user.use(..)
|
|
||||||
res.locals.processed = true;
|
|
||||||
next(err); // this works because err is in normal case undefined and that is the same as no parameter
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ const checkHl = require('../middleware/permission-check').checkHl;
|
||||||
|
|
||||||
const routerHandling = require('../middleware/router-handling');
|
const routerHandling = require('../middleware/router-handling');
|
||||||
const idValidator = require('../middleware/validators').idValidator;
|
const idValidator = require('../middleware/validators').idValidator;
|
||||||
|
const resourceLocation = require('../middleware/resource-location').resourceLocation().concat('/rank/');
|
||||||
|
|
||||||
// Mongoose Model using mongoDB
|
// Mongoose Model using mongoDB
|
||||||
const RankModel = require('../models/rank');
|
const RankModel = require('../models/rank');
|
||||||
|
@ -58,7 +59,7 @@ ranks.route('/')
|
||||||
}
|
}
|
||||||
res.status(codes.created);
|
res.status(codes.created);
|
||||||
res.locals.items = rank;
|
res.locals.items = rank;
|
||||||
fs.appendFile(__dirname + '/../resource/rank/' + rank.id + '.png', new Buffer(req.file.buffer),
|
fs.appendFile(resourceLocation + rank._id + '.png', new Buffer(req.file.buffer),
|
||||||
(err) => {
|
(err) => {
|
||||||
if (err) next(err);
|
if (err) next(err);
|
||||||
});
|
});
|
||||||
|
@ -102,7 +103,7 @@ ranks.route('/:id')
|
||||||
req.body.$inc = {__v: 1};
|
req.body.$inc = {__v: 1};
|
||||||
|
|
||||||
if (req.file) {
|
if (req.file) {
|
||||||
const file = __dirname + '/../resource/rank/' + req.body._id + '.png';
|
const file = resourceLocation + req.body._id + '.png';
|
||||||
fs.unlink(file, (err) => {
|
fs.unlink(file, (err) => {
|
||||||
if (err) next(err);
|
if (err) next(err);
|
||||||
fs.appendFile(file, new Buffer(req.file.buffer),
|
fs.appendFile(file, new Buffer(req.file.buffer),
|
||||||
|
|
|
@ -14,6 +14,9 @@ const UserModel = require('../models/user');
|
||||||
const signatures = new express.Router();
|
const signatures = new express.Router();
|
||||||
|
|
||||||
// routes **********************
|
// routes **********************
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
signatures.route('/:id')
|
signatures.route('/:id')
|
||||||
// does not use idValidator since it works by username
|
// does not use idValidator since it works by username
|
||||||
.get((req, res, next) => {
|
.get((req, res, next) => {
|
||||||
|
|
|
@ -15,6 +15,7 @@ const checkHl = require('../middleware/permission-check').checkHl;
|
||||||
|
|
||||||
const routerHandling = require('../middleware/router-handling');
|
const routerHandling = require('../middleware/router-handling');
|
||||||
const idValidator = require('../middleware/validators').idValidator;
|
const idValidator = require('../middleware/validators').idValidator;
|
||||||
|
const resourceLocation = require('../middleware/resource-location').resourceLocation().concat('/squad/');
|
||||||
|
|
||||||
// Mongoose Model using mongoDB
|
// Mongoose Model using mongoDB
|
||||||
const SquadModel = require('../models/squad');
|
const SquadModel = require('../models/squad');
|
||||||
|
@ -58,10 +59,10 @@ squads.route('/')
|
||||||
}
|
}
|
||||||
res.status(codes.created);
|
res.status(codes.created);
|
||||||
res.locals.items = squad;
|
res.locals.items = squad;
|
||||||
fs.appendFile(__dirname + '/../resource/squad/' + squad.id + '.png', new Buffer(req.file.buffer), (err) => {
|
fs.appendFile(resourceLocation.concat(squad._id).concat('.png'),
|
||||||
if (err) next(err);
|
new Buffer(req.file.buffer), (err) => {
|
||||||
});
|
next(err);
|
||||||
next();
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const err = new Error('no image file provided');
|
const err = new Error('no image file provided');
|
||||||
|
@ -105,7 +106,8 @@ squads.route('/:id')
|
||||||
req.body.$inc = {__v: 1};
|
req.body.$inc = {__v: 1};
|
||||||
|
|
||||||
if (req.file) {
|
if (req.file) {
|
||||||
const file = __dirname + '/../resource/squad/' + req.body._id + '.png';
|
const file = resourceLocation.concat(req.params.id)
|
||||||
|
.concat('.png');
|
||||||
fs.unlink(file, (err) => {
|
fs.unlink(file, (err) => {
|
||||||
if (err) next(err);
|
if (err) next(err);
|
||||||
fs.appendFile(file, new Buffer(req.file.buffer), (err) => {
|
fs.appendFile(file, new Buffer(req.file.buffer), (err) => {
|
||||||
|
@ -139,14 +141,13 @@ squads.route('/:id')
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete graphic
|
// delete graphic
|
||||||
fs.unlink(__dirname + '/../resource/squad/' + req.params.id + '.png', (err) => {
|
fs.unlink(resourceLocation.concat(req.params.id)
|
||||||
if (err) next(err);
|
.concat('.png'), (err) => {
|
||||||
|
// we don't set res.locals.items and thus it will send a 204 (no content) at the end. see last handler
|
||||||
|
res.locals.processed = true;
|
||||||
|
next(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
// we don't set res.locals.items and thus it will send a 204 (no content) at the end. see last handler
|
|
||||||
// user.use(..)
|
|
||||||
res.locals.processed = true;
|
|
||||||
next(err); // this works because err is in normal case undefined and that is the same as no parameter
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ const offsetlimitMiddleware = require('../middleware/limitoffset-middleware-mong
|
||||||
const filterHandlerCreator = require('../middleware/filter-handler-mongo');
|
const filterHandlerCreator = require('../middleware/filter-handler-mongo');
|
||||||
const routerHandling = require('../middleware/router-handling');
|
const routerHandling = require('../middleware/router-handling');
|
||||||
const idValidator = require('../middleware/validators').idValidator;
|
const idValidator = require('../middleware/validators').idValidator;
|
||||||
|
const resourceLocation = require('../middleware/resource-location').resourceLocation().concat('/signature/');
|
||||||
|
|
||||||
// Mongoose Model using mongoDB
|
// Mongoose Model using mongoDB
|
||||||
const UserModel = require('../models/user');
|
const UserModel = require('../models/user');
|
||||||
|
@ -172,12 +173,12 @@ users.route('/:id')
|
||||||
AwardingModel.find({userId: req.params.id}).remove().exec();
|
AwardingModel.find({userId: req.params.id}).remove().exec();
|
||||||
|
|
||||||
// check if signature exists and delete compressed and uncompressed file
|
// check if signature exists and delete compressed and uncompressed file
|
||||||
const fileMinified = __dirname + '/../resource/signature/' + req.params.id + '.png';
|
const fileMinified = resourceLocation + req.params.id + '.png';
|
||||||
if (fs.existsSync(fileMinified)) {
|
if (fs.existsSync(fileMinified)) {
|
||||||
fs.unlink(fileMinified, (err) => {
|
fs.unlink(fileMinified, (err) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const file = __dirname + '/../resource/signature/big/' + req.params.id + '.png';
|
const file = resourceLocation + 'big/' + req.params.id + '.png';
|
||||||
if (fs.existsSync(file)) {
|
if (fs.existsSync(file)) {
|
||||||
fs.unlink(file, (err) => {
|
fs.unlink(file, (err) => {
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,6 +17,7 @@ const checkMT = require('../middleware/permission-check').checkMT;
|
||||||
|
|
||||||
const routerHandling = require('../middleware/router-handling');
|
const routerHandling = require('../middleware/router-handling');
|
||||||
const idValidator = require('../middleware/validators').idValidator;
|
const idValidator = require('../middleware/validators').idValidator;
|
||||||
|
const resourceLocation = require('../middleware/resource-location').resourceLocation().concat('/logs/');
|
||||||
|
|
||||||
// log paser tool
|
// log paser tool
|
||||||
const parseWarLog = require('../tools/log-parse-tool');
|
const parseWarLog = require('../tools/log-parse-tool');
|
||||||
|
@ -99,7 +100,7 @@ wars.route('/')
|
||||||
LogBudgetModel.create(statsResult.budget, () => {
|
LogBudgetModel.create(statsResult.budget, () => {
|
||||||
LogTransportModel.create(statsResult.transport, () => {
|
LogTransportModel.create(statsResult.transport, () => {
|
||||||
LogPointsModel.create(statsResult.points, () => {
|
LogPointsModel.create(statsResult.points, () => {
|
||||||
const folderName = __dirname + '/../resource/logs/' + war._id;
|
const folderName = resourceLocation.concat(war._id);
|
||||||
mkdirp(folderName, (err) => {
|
mkdirp(folderName, (err) => {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
|
|
||||||
|
@ -189,7 +190,7 @@ wars.route('/:id')
|
||||||
LogPointsModel.find({war: item._id}).remove().exec();
|
LogPointsModel.find({war: item._id}).remove().exec();
|
||||||
|
|
||||||
// check if logfiles exist and delete from fs
|
// check if logfiles exist and delete from fs
|
||||||
const warDir = __dirname + '/../resource/logs/' + req.params.id;
|
const warDir = resourceLocation + req.params.id;
|
||||||
|
|
||||||
if (fs.existsSync(warDir)) {
|
if (fs.existsSync(warDir)) {
|
||||||
const cleanLog = warDir + '/clean.log';
|
const cleanLog = warDir + '/clean.log';
|
||||||
|
|
|
@ -24,7 +24,6 @@ const checkAdmin = require('./middleware/permission-check').checkAdmin;
|
||||||
const signatureCronJob = require('./cron-job/cron').cronJobSignature;
|
const signatureCronJob = require('./cron-job/cron').cronJobSignature;
|
||||||
const backupCronJob = require('./cron-job/cron').cronJobBackup;
|
const backupCronJob = require('./cron-job/cron').cronJobBackup;
|
||||||
|
|
||||||
|
|
||||||
// router modules
|
// router modules
|
||||||
const authenticateRouter = require('./routes/authenticate');
|
const authenticateRouter = require('./routes/authenticate');
|
||||||
const accountRouter = require('./routes/account');
|
const accountRouter = require('./routes/account');
|
||||||
|
@ -116,6 +115,7 @@ switch (process.env.NODE_ENV) {
|
||||||
const MongodbMemoryServer = require('mongodb-memory-server').default;
|
const MongodbMemoryServer = require('mongodb-memory-server').default;
|
||||||
const mongoServer = new MongodbMemoryServer();
|
const mongoServer = new MongodbMemoryServer();
|
||||||
mongoose.Promise = Promise;
|
mongoose.Promise = Promise;
|
||||||
|
app.resourcePath = ''
|
||||||
mongoServer.getConnectionString().then((mongoUri) => {
|
mongoServer.getConnectionString().then((mongoUri) => {
|
||||||
mongoose.connect(mongoUri);
|
mongoose.connect(mongoUri);
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ const codes = require('../routes/http-codes');
|
||||||
|
|
||||||
// standard input/output file extension
|
// standard input/output file extension
|
||||||
const fileExt = '.png';
|
const fileExt = '.png';
|
||||||
const resourceDir = __dirname + '/../resource/';
|
const resourceDir = require('../middleware/resource-location').resourceLocation();
|
||||||
|
|
||||||
|
|
||||||
let createSignature = (userId, res, next) => {
|
let createSignature = (userId, res, next) => {
|
||||||
|
|
Loading…
Reference in New Issue