@@ -15,6 +15,7 @@ import { DatasetTool } from '../src/entity/dataset/DatasetTool';
1515import { Source , SourceMember } from '../src/entity' ;
1616import { SourceMemberRoles } from '../src/roles' ;
1717import { sourcesFixture } from './fixture/source' ;
18+ import { MAX_STACK_ITEMS } from '../src/common/constants' ;
1819
1920let con : DataSource ;
2021let state : GraphQLTestingState ;
@@ -242,6 +243,44 @@ describe('mutation addSourceStack', () => {
242243
243244 expect ( res . errors ?. [ 0 ] ?. message ) . toBe ( 'Stack can only be added to Squads' ) ;
244245 } ) ;
246+
247+ it ( 'should prevent adding more than maximum stack items to squad' , async ( ) => {
248+ loggedUser = '1' ;
249+ await con . getRepository ( SourceMember ) . save ( {
250+ userId : '1' ,
251+ sourceId : 'squad' ,
252+ role : SourceMemberRoles . Admin ,
253+ referralToken : 'token1' ,
254+ } ) ;
255+
256+ const tools = await con . getRepository ( DatasetTool ) . save (
257+ Array . from ( { length : MAX_STACK_ITEMS } , ( _ , index ) => ( {
258+ title : `Squad Tool ${ index } ` ,
259+ titleNormalized : `squadtool${ index } ` ,
260+ faviconSource : 'none' ,
261+ } ) ) ,
262+ ) ;
263+
264+ await con . getRepository ( SourceStack ) . save (
265+ tools . map ( ( tool , index ) => ( {
266+ sourceId : 'squad' ,
267+ toolId : tool . id ,
268+ position : index ,
269+ createdById : '1' ,
270+ } ) ) ,
271+ ) ;
272+
273+ const res = await client . mutate ( MUTATION , {
274+ variables : {
275+ sourceId : 'squad' ,
276+ input : { title : 'Node.js' } ,
277+ } ,
278+ } ) ;
279+
280+ expect ( res . errors ?. [ 0 ] ?. message ) . toBe (
281+ `Squads can have a maximum of ${ MAX_STACK_ITEMS } items in their stack` ,
282+ ) ;
283+ } ) ;
245284} ) ;
246285
247286describe ( 'mutation updateSourceStack' , ( ) => {
0 commit comments