forked from premieroctet/openchakra
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aftral[#likes]: added likes on resources
- Loading branch information
1 parent
f4280f6
commit 41f2cae
Showing
5 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const mongoose = require('mongoose') | ||
const { MONGOOSE_OPTIONS, loadFromDb } = require('../../server/utils/database') | ||
require('../../server/plugins/aftral-lms/functions') | ||
const User = require('../../server/models/User') | ||
const Resource = require('../../server/models/Resource') | ||
const Sequence = require('../../server/models/Sequence') | ||
const Module = require('../../server/models/Module') | ||
const Program = require('../../server/models/Program') | ||
const Session = require('../../server/models/Session') | ||
const ProductCode = require('../../server/models/ProductCode') | ||
const Block = require('../../server/models/Block') | ||
const { ROLE_APPRENANT, ROLE_CONCEPTEUR } = require('../../server/plugins/aftral-lms/consts') | ||
|
||
jest.setTimeout(60000) | ||
|
||
describe('User', () => { | ||
beforeAll(async () => { | ||
await mongoose.connect(`mongodb://localhost/aftral-lms`, MONGOOSE_OPTIONS) | ||
}) | ||
afterAll(async () => { | ||
await mongoose.connection.close() | ||
}) | ||
it('must return if resource is mine', async () => { | ||
const user = await User.findOne({ role: ROLE_APPRENANT }) | ||
const concepteur = await User.findOne({role: ROLE_CONCEPTEUR}) | ||
let [u] = await loadFromDb({ model: 'user', fields: ['resources'], user, id:user._id }) | ||
let resources = await loadFromDb({ model: 'resource', fields: ['likes','dislikes', 'liked', 'likes_count', 'dislikes_count'], user:concepteur}) | ||
resources = resources.filter(r=> { | ||
return r.likes.length>0 | ||
}) | ||
console.log(resources[0].likes[0]._id, resources) | ||
console.log(user._id) | ||
}) | ||
}) |