@@ -7,10 +7,10 @@ import request from 'supertest'
77import { HttpError } from './error'
88import { Git } from './git'
99import { getSessionStack } from './middleware'
10- import { App , CodeRepo , Repo , SealedSecret } from './otomi-models'
11- import { RepoService } from './services/RepoService'
10+ import { App , CodeRepo , SealedSecret } from './otomi-models'
1211import * as getValuesSchemaModule from './utils'
1312import TestAgent from 'supertest/lib/agent'
13+ import { FileStore } from './fileStore/file-store'
1414
1515const platformAdminToken = getToken ( [ 'platform-admin' ] )
1616const teamAdminToken = getToken ( [ 'team-admin' , 'team-team1' ] )
@@ -40,22 +40,33 @@ describe('API authz tests', () => {
4040 beforeAll ( async ( ) => {
4141 const _otomiStack = await getSessionStack ( )
4242 _otomiStack . git = mockDeep < Git > ( )
43- _otomiStack . transformApps = jest . fn ( ) . mockReturnValue ( [ ] )
44- _otomiStack . repoService = new RepoService ( { } as Repo )
43+ _otomiStack . fileStore = new FileStore ( )
4544 otomiStack = _otomiStack as jest . Mocked < OtomiStack >
4645
4746 otomiStack . saveTeam = jest . fn ( ) . mockResolvedValue ( undefined )
48- otomiStack . doRepoDeployment = jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( ) )
49- otomiStack . doTeamDeployment = jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( ) )
50- otomiStack . isLoaded = true
51- await otomiStack . createTeam ( {
52- name : 'team1' ,
53- resourceQuota : [ ] ,
54- } )
55- await otomiStack . createTeam ( {
56- name : 'team2' ,
57- resourceQuota : [ ] ,
47+ otomiStack . doDeleteDeployment = jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( ) )
48+ otomiStack . doDeployment = jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( ) )
49+ otomiStack . fileStore . set ( 'env/teams/team1/settings.yaml' , {
50+ kind : 'AplTeamSettingSet' ,
51+ spec : { } ,
52+ metadata : {
53+ name : 'team1' ,
54+ labels : {
55+ 'apl.io/teamId' : 'team1' ,
56+ } ,
57+ } ,
58+ } )
59+ otomiStack . fileStore . set ( 'env/teams/team2/settings.yaml' , {
60+ kind : 'AplTeamSettingSet' ,
61+ spec : { } ,
62+ metadata : {
63+ name : 'team2' ,
64+ labels : {
65+ 'apl.io/teamId' : 'team2' ,
66+ } ,
67+ } ,
5868 } )
69+ otomiStack . isLoaded = true
5970 app = await initApp ( otomiStack )
6071 agent = request . agent ( app )
6172 agent . set ( 'Accept' , 'application/json' )
@@ -92,6 +103,7 @@ describe('API authz tests', () => {
92103 } )
93104
94105 test ( 'platform admin can update team self-service-flags' , async ( ) => {
106+ jest . spyOn ( otomiStack , 'editTeam' ) . mockReturnValue ( { } as any )
95107 await agent
96108 . put ( '/v1/teams/team1' )
97109 . send ( {
@@ -746,6 +758,7 @@ describe('API authz tests', () => {
746758 } )
747759
748760 test ( 'platform admin can update policies' , async ( ) => {
761+ jest . spyOn ( otomiStack , 'editAplPolicy' ) . mockReturnValue ( { } as any )
749762 await agent
750763 . put ( '/v1/teams/team1/policies/disallow-selinux' )
751764 . send ( data )
@@ -1031,7 +1044,7 @@ describe('API authz tests', () => {
10311044 } )
10321045
10331046 test ( 'platform admin can get specific agent' , async ( ) => {
1034- jest . spyOn ( otomiStack , 'getAplAgent' ) . mockResolvedValue ( { } as any )
1047+ jest . spyOn ( otomiStack , 'getAplAgent' ) . mockReturnValue ( { } as any )
10351048 await agent
10361049 . get ( '/alpha/teams/team1/agents/test-agent' )
10371050 . set ( 'Authorization' , `Bearer ${ platformAdminToken } ` )
@@ -1040,7 +1053,7 @@ describe('API authz tests', () => {
10401053 } )
10411054
10421055 test ( 'team admin can get specific agent' , async ( ) => {
1043- jest . spyOn ( otomiStack , 'getAplAgent' ) . mockResolvedValue ( { } as any )
1056+ jest . spyOn ( otomiStack , 'getAplAgent' ) . mockReturnValue ( { } as any )
10441057 await agent
10451058 . get ( '/alpha/teams/team1/agents/test-agent' )
10461059 . set ( 'Authorization' , `Bearer ${ teamAdminToken } ` )
@@ -1049,7 +1062,7 @@ describe('API authz tests', () => {
10491062 } )
10501063
10511064 test ( 'team member can get specific agent' , async ( ) => {
1052- jest . spyOn ( otomiStack , 'getAplAgent' ) . mockResolvedValue ( { } as any )
1065+ jest . spyOn ( otomiStack , 'getAplAgent' ) . mockReturnValue ( { } as any )
10531066 await agent
10541067 . get ( '/alpha/teams/team1/agents/test-agent' )
10551068 . set ( 'Authorization' , `Bearer ${ teamMemberToken } ` )
0 commit comments