@@ -4,6 +4,8 @@ const service = app.service('contributions');
44const userService = app . service ( 'users' ) ;
55const notificationService = app . service ( 'notifications' ) ;
66const categoryService = app . service ( 'categories' ) ;
7+ const usersService = app . service ( 'users' ) ;
8+ const usersettingsService = app . service ( 'usersettings' ) ;
79const { userData, adminData } = require ( '../assets/users' ) ;
810const {
911 contributionData,
@@ -172,6 +174,46 @@ describe('\'contributions\' service', () => {
172174 'does not populate'
173175 ) ;
174176 } ) ;
177+
178+ describe ( 'of an author' , ( ) => {
179+ let author ;
180+ beforeEach ( async ( ) => {
181+ author = await usersService . create ( {
182+ 183+ name : 'Bad guy'
184+ } ) ;
185+ const data = { ...contributionData , userId : author . _id } ;
186+ await service . create ( data ) ;
187+ } ) ;
188+
189+ context ( 'who is not blacklisted' , ( ) => {
190+ it ( 'contribution is included' , async ( ) => {
191+ const contributions = await service . find ( params ) ;
192+ assert . equal ( contributions . total , 2 ) ;
193+ } ) ;
194+ } ) ;
195+
196+ context ( 'who is blacklisted' , ( ) => {
197+ beforeEach ( async ( ) => {
198+ await usersettingsService . create ( {
199+ userId : user . _id ,
200+ blacklist : [ author . _id ]
201+ } ) ;
202+ } ) ;
203+
204+ it ( 'contribution is filtered' , async ( ) => {
205+ const contributions = await service . find ( params ) ;
206+ assert . equal ( contributions . total , 1 ) ;
207+ } ) ;
208+
209+ context ( 'but if user is not authenticated' , ( ) => {
210+ it ( 'contribution is filtered' , async ( ) => {
211+ const contributions = await service . find ( ) ;
212+ assert . equal ( contributions . total , 2 ) ;
213+ } ) ;
214+ } ) ;
215+ } ) ;
216+ } ) ;
175217 } ) ;
176218
177219 describe ( 'contributions find by slug' , ( ) => {
0 commit comments