@@ -11,7 +11,7 @@ import {
1111} from 'src/otomi-models'
1212import OtomiStack from 'src/otomi-stack'
1313import { loadSpec } from './app'
14- import { PublicUrlExists } from './error'
14+ import { PublicUrlExists , ValidationError } from './error'
1515import { Git } from './git'
1616import { RepoService } from './services/RepoService'
1717import { TeamConfigService } from './services/TeamConfigService'
@@ -208,6 +208,109 @@ describe('Data validation', () => {
208208 expect ( createItemSpy . mock . calls [ 0 ] [ 0 ] . spec . password ) . toEqual ( myPassword )
209209 createItemSpy . mockRestore ( )
210210 } )
211+
212+ test ( 'should throw ValidationError when team name exceeds 9 characters' , async ( ) => {
213+ const teamData : AplTeamSettingsRequest = {
214+ kind : 'AplTeamSettingSet' ,
215+ metadata : {
216+ name : 'verylongteamname' ,
217+ labels : {
218+ 'apl.io/teamId' : 'verylongteamname' ,
219+ } ,
220+ } ,
221+ spec : { } ,
222+ }
223+
224+ await expect ( otomiStack . createAplTeam ( teamData , false ) ) . rejects . toThrow (
225+ new ValidationError ( 'Team name must not exceed 9 characters' ) ,
226+ )
227+ } )
228+
229+ test ( 'should not throw ValidationError when team name is exactly 9 characters' , async ( ) => {
230+ const teamSettings = {
231+ kind : 'AplTeamSettingSet' ,
232+ metadata : {
233+ name : 'ninechars' ,
234+ labels : {
235+ 'apl.io/teamId' : 'ninechars' ,
236+ } ,
237+ } ,
238+ spec : { } ,
239+ status : { } ,
240+ }
241+
242+ const createItemSpy = jest . spyOn ( otomiStack . repoService , 'createTeamConfig' ) . mockReturnValue ( {
243+ builds : [ ] ,
244+ codeRepos : [ ] ,
245+ workloads : [ ] ,
246+ services : [ ] ,
247+ sealedsecrets : [ ] ,
248+ backups : [ ] ,
249+ projects : [ ] ,
250+ netpols : [ ] ,
251+ settings : teamSettings ,
252+ apps : [ ] ,
253+ policies : [ ] ,
254+ workloadValues : [ ] ,
255+ } as TeamConfig )
256+
257+ const teamData : AplTeamSettingsRequest = {
258+ kind : 'AplTeamSettingSet' ,
259+ metadata : {
260+ name : 'ninechars' ,
261+ labels : {
262+ 'apl.io/teamId' : 'ninechars' ,
263+ } ,
264+ } ,
265+ spec : { } ,
266+ }
267+
268+ await expect ( otomiStack . createAplTeam ( teamData , false ) ) . resolves . not . toThrow ( )
269+ createItemSpy . mockRestore ( )
270+ } )
271+
272+ test ( 'should not throw ValidationError when team name is less than 9 characters' , async ( ) => {
273+ const teamSettings = {
274+ kind : 'AplTeamSettingSet' ,
275+ metadata : {
276+ name : 'short' ,
277+ labels : {
278+ 'apl.io/teamId' : 'short' ,
279+ } ,
280+ } ,
281+ spec : { } ,
282+ status : { } ,
283+ }
284+
285+ const createItemSpy = jest . spyOn ( otomiStack . repoService , 'createTeamConfig' ) . mockReturnValue ( {
286+ builds : [ ] ,
287+ codeRepos : [ ] ,
288+ workloads : [ ] ,
289+ services : [ ] ,
290+ sealedsecrets : [ ] ,
291+ backups : [ ] ,
292+ projects : [ ] ,
293+ netpols : [ ] ,
294+ settings : teamSettings ,
295+ apps : [ ] ,
296+ policies : [ ] ,
297+ workloadValues : [ ] ,
298+ } as TeamConfig )
299+
300+ const teamData : AplTeamSettingsRequest = {
301+ kind : 'AplTeamSettingSet' ,
302+ metadata : {
303+ name : 'short' ,
304+ labels : {
305+ 'apl.io/teamId' : 'short' ,
306+ } ,
307+ } ,
308+ spec : { } ,
309+ }
310+
311+ await expect ( otomiStack . createAplTeam ( teamData , false ) ) . resolves . not . toThrow ( )
312+ createItemSpy . mockRestore ( )
313+ } )
211314} )
212315
213316describe ( 'Work with values' , ( ) => {
0 commit comments