set height on new publishes to current height in Claim db
This commit is contained in:
parent
d2eaaae759
commit
e2a3039e4e
10 changed files with 141 additions and 87 deletions
|
@ -17,6 +17,7 @@
|
|||
"start:build": "builder run start",
|
||||
"test": "mocha --recursive",
|
||||
"test:no-lbc": "npm test -- --grep @usesLbc --invert",
|
||||
"test:server": "mocha --recursive './server/**/*.test.js'",
|
||||
"transpile": "builder concurrent transpile:server transpile:client transpile:client_custom",
|
||||
"transpile:dev": "builder concurrent transpile:server:dev transpile:client:dev transpile:client_custom:dev",
|
||||
"transpile:server": "babel server/render/src -d server/render/build",
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
const chai = require('chai');
|
||||
const expect = chai.expect;
|
||||
|
||||
describe('#parsePublishApiRequestBody()', function () {
|
||||
const parsePublishApiRequestBody = require('./parsePublishApiRequestBody.js');
|
||||
|
||||
it('should throw an error if no body', function () {
|
||||
expect(parsePublishApiRequestBody.bind(this, null)).to.throw();
|
||||
});
|
||||
|
||||
it('should throw an error if no body.name', function () {
|
||||
const bodyNoName = {};
|
||||
expect(parsePublishApiRequestBody.bind(this, bodyNoName)).to.throw();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,51 @@
|
|||
const chai = require('chai');
|
||||
const expect = chai.expect;
|
||||
|
||||
describe('#parsePublishApiRequestFiles()', function () {
|
||||
const parsePublishApiRequestFiles = require('./parsePublishApiRequestFiles.js');
|
||||
|
||||
it('should throw an error if no files', function () {
|
||||
expect(parsePublishApiRequestFiles.bind(this, null)).to.throw();
|
||||
});
|
||||
|
||||
it('should throw an error if no files.file', function () {
|
||||
const filesNoFile = {};
|
||||
expect(parsePublishApiRequestFiles.bind(this, filesNoFile)).to.throw();
|
||||
});
|
||||
|
||||
it('should throw an error if file.size is too large', function () {
|
||||
const filesTooBig = {
|
||||
file: {
|
||||
name: 'file.jpg',
|
||||
path: '/path/to/file.jpg',
|
||||
type: 'image/jpg',
|
||||
size: 10000001,
|
||||
},
|
||||
};
|
||||
expect(parsePublishApiRequestFiles.bind(this, filesTooBig)).to.throw();
|
||||
});
|
||||
|
||||
it('should throw error if not an accepted file type', function () {
|
||||
const filesWrongType = {
|
||||
file: {
|
||||
name: 'file.jpg',
|
||||
path: '/path/to/file.jpg',
|
||||
type: 'someType/ext',
|
||||
size: 10000000,
|
||||
},
|
||||
};
|
||||
expect(parsePublishApiRequestFiles.bind(this, filesWrongType)).to.throw();
|
||||
});
|
||||
|
||||
it('should throw NO error if no problems', function () {
|
||||
const filesNoProblems = {
|
||||
file: {
|
||||
name: 'file.jpg',
|
||||
path: '/path/to/file.jpg',
|
||||
type: 'image/jpg',
|
||||
size: 10000000,
|
||||
},
|
||||
};
|
||||
expect(parsePublishApiRequestFiles.bind(this, filesNoProblems)).to.not.throw();
|
||||
});
|
||||
});
|
|
@ -401,5 +401,10 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
|
|||
});
|
||||
};
|
||||
|
||||
Claim.getCurrentHeight = function () {
|
||||
return this
|
||||
.max('height');
|
||||
};
|
||||
|
||||
return Claim;
|
||||
};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const db = require('../index.js');
|
||||
|
||||
const createClaimRecordDataAfterPublish = (certificateId, channelName, fileName, fileType, publishParams, publishResults) => {
|
||||
const {
|
||||
name,
|
||||
|
@ -17,21 +19,24 @@ const createClaimRecordDataAfterPublish = (certificateId, channelName, fileName,
|
|||
nout,
|
||||
} = publishResults;
|
||||
|
||||
return {
|
||||
name,
|
||||
claimId,
|
||||
title,
|
||||
description,
|
||||
address,
|
||||
thumbnail,
|
||||
outpoint : `${txid}:${nout}`,
|
||||
height : 0,
|
||||
contentType: fileType,
|
||||
nsfw,
|
||||
amount,
|
||||
certificateId,
|
||||
channelName,
|
||||
};
|
||||
return db.Claim.getCurrentHeight()
|
||||
.then(height => {
|
||||
return {
|
||||
name,
|
||||
claimId,
|
||||
title,
|
||||
description,
|
||||
address,
|
||||
thumbnail,
|
||||
outpoint : `${txid}:${nout}`,
|
||||
height,
|
||||
contentType: fileType,
|
||||
nsfw,
|
||||
amount,
|
||||
certificateId,
|
||||
channelName,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
|
42
server/models/utils/returnShortId.test.js
Normal file
42
server/models/utils/returnShortId.test.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
const chai = require('chai');
|
||||
const expect = chai.expect;
|
||||
|
||||
describe('#parsePublishApiRequestBody()', function () {
|
||||
const returnShortId = require('./returnShortId.js');
|
||||
let dummyClaimsArray;
|
||||
let dummyLongId;
|
||||
|
||||
it('should thow an error if the claimId is not in the claim list', function () {
|
||||
dummyClaimsArray = [
|
||||
{claimId: 'a123456789'},
|
||||
{claimId: 'b123456789'},
|
||||
{claimId: 'c123456789'},
|
||||
];
|
||||
dummyLongId = 'xxxxxxxxxx';
|
||||
expect(returnShortId.bind(this, dummyClaimsArray, dummyLongId)).to.throw();
|
||||
});
|
||||
|
||||
it('should return the shortest unique claim id', function () {
|
||||
dummyClaimsArray = [
|
||||
{claimId: 'a123456789'},
|
||||
{claimId: 'b123456789'},
|
||||
{claimId: 'c123456789'},
|
||||
];
|
||||
dummyLongId = 'c123456789';
|
||||
expect(returnShortId(dummyClaimsArray, dummyLongId)).to.equal('c');
|
||||
});
|
||||
|
||||
it('if there is a conflict between unqiue ids, it should give preference to the one with the lowest height', function () {
|
||||
dummyClaimsArray = [
|
||||
{claimId: 'a123456789', height: 10},
|
||||
{claimId: 'ab12345678', height: 11},
|
||||
{claimId: 'ab12341111', height: 12},
|
||||
];
|
||||
dummyLongId = 'a123456789';
|
||||
expect(returnShortId(dummyClaimsArray, dummyLongId)).to.equal('a');
|
||||
dummyLongId = 'ab12345678';
|
||||
expect(returnShortId(dummyClaimsArray, dummyLongId)).to.equal('ab');
|
||||
dummyLongId = 'ab12341111';
|
||||
expect(returnShortId(dummyClaimsArray, dummyLongId)).to.equal('ab12341');
|
||||
});
|
||||
});
|
|
@ -1,3 +1,5 @@
|
|||
require('../module-alias-boilerplate.js');
|
||||
|
||||
const chai = require('chai');
|
||||
const expect = chai.expect;
|
||||
const chaiHttp = require('chai-http');
|
4
test/module-alias-boilerplate.js
Normal file
4
test/module-alias-boilerplate.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
// set up aliases
|
||||
const moduleAlias = require('module-alias');
|
||||
const customAliases = require('../utils/createModuleAliases.js')();
|
||||
moduleAlias.addAliases(customAliases);
|
|
@ -1,72 +0,0 @@
|
|||
const chai = require('chai');
|
||||
const expect = chai.expect;
|
||||
|
||||
describe('publish utils', function () {
|
||||
|
||||
describe('#parsePublishApiRequestBody()', function () {
|
||||
const parsePublishApiRequestBody = require('../../../server/controllers/api/claim/publish/parsePublishApiRequestBody.js');
|
||||
|
||||
it('should throw an error if no body', function () {
|
||||
expect(parsePublishApiRequestBody.bind(this, null)).to.throw();
|
||||
});
|
||||
|
||||
it('should throw an error if no body.name', function () {
|
||||
const bodyNoName = {};
|
||||
expect(parsePublishApiRequestBody.bind(this, bodyNoName)).to.throw();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#parsePublishApiRequestFiles()', function () {
|
||||
const parsePublishApiRequestFiles = require('../../../server/controllers/api/claim/publish/parsePublishApiRequestFiles.js');
|
||||
|
||||
it('should throw an error if no files', function () {
|
||||
expect(parsePublishApiRequestFiles.bind(this, null)).to.throw();
|
||||
});
|
||||
|
||||
it('should throw an error if no files.file', function () {
|
||||
const filesNoFile = {};
|
||||
expect(parsePublishApiRequestFiles.bind(this, filesNoFile)).to.throw();
|
||||
});
|
||||
|
||||
it('should throw an error if file.size is too large', function () {
|
||||
const filesTooBig = {
|
||||
file: {
|
||||
name: 'file.jpg',
|
||||
path: '/path/to/file.jpg',
|
||||
type: 'image/jpg',
|
||||
size: 10000001,
|
||||
},
|
||||
};
|
||||
expect(parsePublishApiRequestFiles.bind(this, filesTooBig)).to.throw();
|
||||
});
|
||||
|
||||
it('should throw error if not an accepted file type', function () {
|
||||
const filesWrongType = {
|
||||
file: {
|
||||
name: 'file.jpg',
|
||||
path: '/path/to/file.jpg',
|
||||
type: 'someType/ext',
|
||||
size: 10000000,
|
||||
},
|
||||
};
|
||||
expect(parsePublishApiRequestFiles.bind(this, filesWrongType)).to.throw();
|
||||
});
|
||||
|
||||
it('should throw NO error if no problems', function () {
|
||||
const filesNoProblems = {
|
||||
file: {
|
||||
name: 'file.jpg',
|
||||
path: '/path/to/file.jpg',
|
||||
type: 'image/jpg',
|
||||
size: 10000000,
|
||||
},
|
||||
};
|
||||
expect(parsePublishApiRequestFiles.bind(this, filesNoProblems)).to.not.throw();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#parsePublishApiChannel()', function () {
|
||||
it('should pass the tests I write here');
|
||||
});
|
||||
});
|
|
@ -26,6 +26,7 @@ module.exports = () => {
|
|||
let moduleAliases = {};
|
||||
// aliases for configs
|
||||
moduleAliases['@config'] = resolve(`config`);
|
||||
moduleAliases['@devConfig'] = resolve(`devConfig`);
|
||||
|
||||
// create specific aliases for locally defined components
|
||||
moduleAliases = addAlliasesForFolder('containers', moduleAliases);
|
||||
|
|
Loading…
Reference in a new issue