mirror of
https://github.com/wassname/talk.git
synced 2026-08-02 13:10:23 +08:00
+10
-3
@@ -5,7 +5,6 @@ const Assets = require('./assets');
|
||||
const Settings = require('./settings');
|
||||
const { ADD_COMMENT_TAG } = require('../perms/constants');
|
||||
const { ErrNotAuthorized } = require('../errors');
|
||||
const { get, has } = require('lodash');
|
||||
|
||||
const updateModel = async (item_type, query, update) => {
|
||||
// Get the model to update with.
|
||||
@@ -60,8 +59,16 @@ class TagsService {
|
||||
asset = await Assets.findById(id);
|
||||
}
|
||||
|
||||
if (asset && has(asset, 'settings.tags')) {
|
||||
return get(asset, 'settings.tags');
|
||||
// Lodash has issues with determining property existence when the object
|
||||
// is a Mongoose model, this is likely related to how Mongoose proxies the
|
||||
// object, but this concrete check works.
|
||||
if (
|
||||
asset &&
|
||||
asset.settings &&
|
||||
asset.settings.tags &&
|
||||
Array.isArray(asset.settings.tags)
|
||||
) {
|
||||
return asset.settings.tags;
|
||||
}
|
||||
|
||||
// Extract the tags from the settings object.
|
||||
|
||||
@@ -2,6 +2,7 @@ const TagsService = require('../../../services/tags');
|
||||
const UsersService = require('../../../services/users');
|
||||
const SettingsService = require('../../../services/settings');
|
||||
const CommentModel = require('../../../models/comment');
|
||||
const AssetModel = require('../../../models/asset');
|
||||
const Context = require('../../../graph/context');
|
||||
|
||||
const chai = require('chai');
|
||||
@@ -18,6 +19,24 @@ describe('services.TagsService', () => {
|
||||
'1Coral!!',
|
||||
'Stampi'
|
||||
);
|
||||
// We don't care about the asset value, just that it exists.
|
||||
await AssetModel.create({
|
||||
id: '123',
|
||||
settings: {
|
||||
tags: [
|
||||
{
|
||||
name: 'TEST',
|
||||
permissions: {
|
||||
public: true,
|
||||
self: true,
|
||||
roles: [],
|
||||
},
|
||||
models: ['COMMENTS'],
|
||||
created_at: new Date(),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
comment = await CommentModel.create({
|
||||
id: '1',
|
||||
body: 'comment 10',
|
||||
@@ -28,6 +47,18 @@ describe('services.TagsService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getAll', () => {
|
||||
it('retrieves tags from the asset', async () => {
|
||||
const tags = await TagsService.getAll({
|
||||
item_type: 'COMMENTS',
|
||||
asset_id: comment.asset_id,
|
||||
});
|
||||
|
||||
expect(tags.length).to.equal(1);
|
||||
expect(tags[0].name).to.equal('TEST');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#add', () => {
|
||||
it('adds a tag', async () => {
|
||||
const id = comment.id;
|
||||
|
||||
Reference in New Issue
Block a user