Correctly determine the status of the asset

This commit is contained in:
Chi Vinh Le
2017-08-02 00:04:11 +07:00
parent 08a491b3a0
commit b972f4305e
6 changed files with 10 additions and 7 deletions
@@ -16,7 +16,7 @@ class ConfigureStreamContainer extends Component {
this.state = {
changed: false,
dirtySettings: props.asset.settings,
closedAt: (props.asset.closedAt === null ? 'open' : 'closed')
closedAt: !props.asset.isClosed ? 'open' : 'closed'
};
this.toggleStatus = this.toggleStatus.bind(this);
@@ -101,7 +101,7 @@ class Stream extends React.Component {
editName
} = this.props;
const {keepCommentBox} = this.state;
const open = asset.closedAt === null;
const open = !asset.isClosed;
// even though the permalinked comment is the highlighted one, we're displaying its parent + replies
let highlightedComment = comment && getTopLevelParent(comment);
@@ -250,7 +250,7 @@ const fragments = {
id
title
url
closedAt
isClosed
created_at
settings {
moderation
+3
View File
@@ -596,6 +596,9 @@ type Asset {
# The date that the asset was closed at.
closedAt: Date
# True if asset is closed.
isClosed: Boolean!
# Summary of all Actions against all entities associated with the Asset.
# (likes, flags, etc.). Requires the `ADMIN` role.
action_summaries: [AssetActionSummary!]
+2 -2
View File
@@ -61,7 +61,7 @@ const AssetSchema = new Schema({
timestamps: {
createdAt: 'created_at',
updatedAt: 'updated_at'
}
},
});
AssetSchema.index({
@@ -79,7 +79,7 @@ AssetSchema.index({
* Returns true if the asset is closed, false else.
*/
AssetSchema.virtual('isClosed').get(function() {
return this.closedAt && this.closedAt.getTime() <= new Date().getTime();
return Boolean(this.closedAt && this.closedAt.getTime() <= new Date().getTime());
});
const Asset = mongoose.model('Asset', AssetSchema);
+2 -2
View File
@@ -43,7 +43,7 @@ describe('/api/v1/assets', () => {
.set(passport.inject({roles: ['ADMIN']}))
.then((res) => {
const body = res.body;
expect(body).to.have.property('count', 2);
expect(body).to.have.property('result');
@@ -129,7 +129,7 @@ describe('/api/v1/assets', () => {
return AssetsService.findOrCreateByUrl('http://test.com')
.then((asset) => {
expect(asset).to.have.property('isClosed', null);
expect(asset).to.have.property('isClosed', false);
expect(asset).to.have.property('closedAt', null);
return chai.request(app)