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
|
||||
public/
|
||||
mongodb-data/
|
||||
resource/
|
||||
api/resource/
|
||||
api/apib/dredd/data/tmp-resource
|
||||
backup/
|
||||
|
||||
# System
|
||||
|
|
|
@ -45,15 +45,12 @@ Create a new squad
|
|||
|
||||
BLUFOR
|
||||
-----BOUNDARY
|
||||
Content-Disposition: form-data; name="image"; filename="image.jpg"
|
||||
Content-Type: image/jpeg
|
||||
Content-Disposition: form-data; name="image"; filename="image.png"
|
||||
Content-Type: image/png
|
||||
Content-Transfer-Encoding: base64
|
||||
|
||||
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
|
||||
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy
|
||||
MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAABAAEDASIA
|
||||
AhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEB
|
||||
AAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AL+AD//Z
|
||||
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlMA
|
||||
QObYZgAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=
|
||||
-----BOUNDARY--
|
||||
|
||||
+ Response 201
|
||||
|
@ -80,15 +77,12 @@ Update squad, identified by its id
|
|||
|
||||
OPFOR
|
||||
-----BOUNDARY
|
||||
Content-Disposition: form-data; name="image"; filename="image.jpg"
|
||||
Content-Type: image/jpeg
|
||||
Content-Disposition: form-data; name="image"; filename="image.png"
|
||||
Content-Type: image/png
|
||||
Content-Transfer-Encoding: base64
|
||||
|
||||
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
|
||||
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy
|
||||
MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAABAAEDASIA
|
||||
AhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEB
|
||||
AAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AL+AD//Z
|
||||
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlMA
|
||||
QObYZgAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=
|
||||
-----BOUNDARY--
|
||||
|
||||
+ 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 = {
|
||||
port: 8091,
|
||||
resourceLocation: __dirname + '/../resource',
|
||||
|
||||
database: {
|
||||
uri: 'mongodb://localhost:27017/',
|
||||
|
@ -19,10 +20,11 @@ module.exports = {
|
|||
dredd: {
|
||||
env: 'dreddTest',
|
||||
port: 3001,
|
||||
resourceLocation: __dirname + '/../apib/dredd/data/tmp-resource',
|
||||
},
|
||||
unit: {
|
||||
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'",
|
||||
"test": "mocha --require ./test/config/spec_helper.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: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",
|
||||
|
|
|
@ -15,6 +15,7 @@ const checkHl = require('../middleware/permission-check').checkHl;
|
|||
|
||||
const routerHandling = require('../middleware/router-handling');
|
||||
const idValidator = require('../middleware/validators').idValidator;
|
||||
const resourceLocation = require('../middleware/resource-location').resourceLocation().concat('/decoration/');
|
||||
|
||||
// Mongoose Model using mongoDB
|
||||
const DecorationModel = require('../models/decoration');
|
||||
|
@ -65,7 +66,7 @@ decoration.route('/')
|
|||
}
|
||||
res.status(codes.created);
|
||||
res.locals.items = decoration;
|
||||
fs.appendFile(__dirname + '/../resource/decoration/' + decoration.id + '.png',
|
||||
fs.appendFile(resourceLocation + decoration._id + '.png',
|
||||
new Buffer(req.file.buffer),
|
||||
(err) => {
|
||||
if (err) next(err);
|
||||
|
@ -109,7 +110,7 @@ decoration.route('/:id')
|
|||
req.body.$inc = {__v: 1};
|
||||
|
||||
if (req.file) {
|
||||
const file = __dirname + '/../resource/decoration/' + req.body._id + '.png';
|
||||
const file = resourceLocation + req.body._id + '.png';
|
||||
fs.unlink(file, (err) => {
|
||||
if (err) next(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();
|
||||
|
||||
// delete graphic
|
||||
fs.unlink(__dirname + '/../resource/decoration/' + req.params.id + '.png',
|
||||
fs.unlink(resourceLocation + req.params.id + '.png',
|
||||
(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 idValidator = require('../middleware/validators').idValidator;
|
||||
const resourceLocation = require('../middleware/resource-location').resourceLocation().concat('/rank/');
|
||||
|
||||
// Mongoose Model using mongoDB
|
||||
const RankModel = require('../models/rank');
|
||||
|
@ -58,7 +59,7 @@ ranks.route('/')
|
|||
}
|
||||
res.status(codes.created);
|
||||
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) => {
|
||||
if (err) next(err);
|
||||
});
|
||||
|
@ -102,7 +103,7 @@ ranks.route('/:id')
|
|||
req.body.$inc = {__v: 1};
|
||||
|
||||
if (req.file) {
|
||||
const file = __dirname + '/../resource/rank/' + req.body._id + '.png';
|
||||
const file = resourceLocation + req.body._id + '.png';
|
||||
fs.unlink(file, (err) => {
|
||||
if (err) next(err);
|
||||
fs.appendFile(file, new Buffer(req.file.buffer),
|
||||
|
|
|
@ -14,6 +14,9 @@ const UserModel = require('../models/user');
|
|||
const signatures = new express.Router();
|
||||
|
||||
// routes **********************
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
signatures.route('/:id')
|
||||
// does not use idValidator since it works by username
|
||||
.get((req, res, next) => {
|
||||
|
|
|
@ -15,6 +15,7 @@ const checkHl = require('../middleware/permission-check').checkHl;
|
|||
|
||||
const routerHandling = require('../middleware/router-handling');
|
||||
const idValidator = require('../middleware/validators').idValidator;
|
||||
const resourceLocation = require('../middleware/resource-location').resourceLocation().concat('/squad/');
|
||||
|
||||
// Mongoose Model using mongoDB
|
||||
const SquadModel = require('../models/squad');
|
||||
|
@ -58,10 +59,10 @@ squads.route('/')
|
|||
}
|
||||
res.status(codes.created);
|
||||
res.locals.items = squad;
|
||||
fs.appendFile(__dirname + '/../resource/squad/' + squad.id + '.png', new Buffer(req.file.buffer), (err) => {
|
||||
if (err) next(err);
|
||||
});
|
||||
next();
|
||||
fs.appendFile(resourceLocation.concat(squad._id).concat('.png'),
|
||||
new Buffer(req.file.buffer), (err) => {
|
||||
next(err);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
const err = new Error('no image file provided');
|
||||
|
@ -105,7 +106,8 @@ squads.route('/:id')
|
|||
req.body.$inc = {__v: 1};
|
||||
|
||||
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) => {
|
||||
if (err) next(err);
|
||||
fs.appendFile(file, new Buffer(req.file.buffer), (err) => {
|
||||
|
@ -139,14 +141,13 @@ squads.route('/:id')
|
|||
}
|
||||
|
||||
// delete graphic
|
||||
fs.unlink(__dirname + '/../resource/squad/' + req.params.id + '.png', (err) => {
|
||||
if (err) next(err);
|
||||
fs.unlink(resourceLocation.concat(req.params.id)
|
||||
.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 routerHandling = require('../middleware/router-handling');
|
||||
const idValidator = require('../middleware/validators').idValidator;
|
||||
const resourceLocation = require('../middleware/resource-location').resourceLocation().concat('/signature/');
|
||||
|
||||
// Mongoose Model using mongoDB
|
||||
const UserModel = require('../models/user');
|
||||
|
@ -172,12 +173,12 @@ users.route('/:id')
|
|||
AwardingModel.find({userId: req.params.id}).remove().exec();
|
||||
|
||||
// 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)) {
|
||||
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)) {
|
||||
fs.unlink(file, (err) => {
|
||||
});
|
||||
|
|
|
@ -17,6 +17,7 @@ const checkMT = require('../middleware/permission-check').checkMT;
|
|||
|
||||
const routerHandling = require('../middleware/router-handling');
|
||||
const idValidator = require('../middleware/validators').idValidator;
|
||||
const resourceLocation = require('../middleware/resource-location').resourceLocation().concat('/logs/');
|
||||
|
||||
// log paser tool
|
||||
const parseWarLog = require('../tools/log-parse-tool');
|
||||
|
@ -99,7 +100,7 @@ wars.route('/')
|
|||
LogBudgetModel.create(statsResult.budget, () => {
|
||||
LogTransportModel.create(statsResult.transport, () => {
|
||||
LogPointsModel.create(statsResult.points, () => {
|
||||
const folderName = __dirname + '/../resource/logs/' + war._id;
|
||||
const folderName = resourceLocation.concat(war._id);
|
||||
mkdirp(folderName, (err) => {
|
||||
if (err) return next(err);
|
||||
|
||||
|
@ -189,7 +190,7 @@ wars.route('/:id')
|
|||
LogPointsModel.find({war: item._id}).remove().exec();
|
||||
|
||||
// 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)) {
|
||||
const cleanLog = warDir + '/clean.log';
|
||||
|
|
|
@ -24,7 +24,6 @@ const checkAdmin = require('./middleware/permission-check').checkAdmin;
|
|||
const signatureCronJob = require('./cron-job/cron').cronJobSignature;
|
||||
const backupCronJob = require('./cron-job/cron').cronJobBackup;
|
||||
|
||||
|
||||
// router modules
|
||||
const authenticateRouter = require('./routes/authenticate');
|
||||
const accountRouter = require('./routes/account');
|
||||
|
@ -116,6 +115,7 @@ switch (process.env.NODE_ENV) {
|
|||
const MongodbMemoryServer = require('mongodb-memory-server').default;
|
||||
const mongoServer = new MongodbMemoryServer();
|
||||
mongoose.Promise = Promise;
|
||||
app.resourcePath = ''
|
||||
mongoServer.getConnectionString().then((mongoUri) => {
|
||||
mongoose.connect(mongoUri);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ const codes = require('../routes/http-codes');
|
|||
|
||||
// standard input/output file extension
|
||||
const fileExt = '.png';
|
||||
const resourceDir = __dirname + '/../resource/';
|
||||
const resourceDir = require('../middleware/resource-location').resourceLocation();
|
||||
|
||||
|
||||
let createSignature = (userId, res, next) => {
|
||||
|
|
Loading…
Reference in New Issue