Skip to content

Commit

Permalink
prettier fix
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mohamed <[email protected]>
  • Loading branch information
muhammadnmuhammad01 committed Jul 31, 2023
1 parent d52d82e commit d00ea30
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class ArgoService implements ArgoServiceApi {
argoInstance.url,
argoInstance.name,
token,
options
options,
);
} catch (error: any) {
return null;
Expand Down Expand Up @@ -176,14 +176,14 @@ export class ArgoService implements ArgoServiceApi {
options?: {
name?: string;
selector?: string;
}
},
): Promise<any> {
let urlSuffix = ""
let urlSuffix = '';
if (options?.name) {
urlSuffix = `/${options.name}`
urlSuffix = `/${options.name}`;
}
if (options?.selector) {
urlSuffix = `?selector=${options.selector}`
urlSuffix = `?selector=${options.selector}`;
}
const requestOptions: RequestInit = {
method: 'GET',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('ArgoCD service', () => {
namespace: 'testNamespace2',
},
},
]
],
}),
);
const resp = await argoService.getArgoAppData(
Expand All @@ -142,29 +142,29 @@ describe('ArgoCD service', () => {
'testToken',
);

expect(resp).toStrictEqual( {
expect(resp).toStrictEqual({
items: [
{
metadata: {
name: "testAppName",
namespace: "testNamespace",
name: 'testAppName',
namespace: 'testNamespace',
instance: {
name: "argoInstance1"
}
}
name: 'argoInstance1',
},
},
},
{
metadata: {
name: "testAppName2",
namespace: "testNamespace2",
name: 'testAppName2',
namespace: 'testNamespace2',
instance: {
name: "argoInstance1"
}
}
}
]
name: 'argoInstance1',
},
},
},
],
});
})
});

it('should get argo app data', async () => {
fetchMock.mockResponseOnce(
Expand All @@ -180,7 +180,7 @@ describe('ArgoCD service', () => {
'https://argoInstance1.com',
'argoInstance1',
'testToken',
{ name: 'testApp' }
{ name: 'testApp' },
);

expect(resp).toStrictEqual({
Expand All @@ -200,7 +200,7 @@ describe('ArgoCD service', () => {
'https://argoInstance1.com',
'argoInstance1',
'testToken',
{ name: 'testApp' }
{ name: 'testApp' },
),
).rejects.toThrow();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('router', () => {
password: 'password',
},
]);
mockGetArgoToken.mockReturnValue("token")
mockGetArgoToken.mockReturnValue('token');
mockGetArgoAppData.mockReturnValue({
items: [
{
Expand All @@ -140,10 +140,10 @@ describe('router', () => {
},
spec: {
source: {
repoURL: "test.repo.url",
path: "source/path"
}
}
repoURL: 'test.repo.url',
path: 'source/path',
},
},
},
{
metadata: {
Expand All @@ -152,20 +152,24 @@ describe('router', () => {
},
spec: {
source: {
repoURL: "test.repo.url.two",
path: "source/path"
}
}
repoURL: 'test.repo.url.two',
path: 'source/path',
},
},
},
]
})
],
});

const response = await request(app).get('/argoInstance/argoInstance1/repo/testrepo/source/testsource')
const response = await request(app).get(
'/argoInstance/argoInstance1/repo/testrepo/source/testsource',
);
expect(response.body).toEqual(false);

const response2 = await request(app).get('/argoInstance/argoInstance1/repo/test.repo.url/source/source%2Fpath')
const response2 = await request(app).get(
'/argoInstance/argoInstance1/repo/test.repo.url/source/source%2Fpath',
);
expect(response2.body).toEqual(true);
})
});

it('delete sends back status of app and project deletion', async () => {
mockDeleteAppandProject.mockResolvedValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function createRouter({
return token;
}

router.get('/allArgoApps/:argoInstanceName', async(request, response) => {
router.get('/allArgoApps/:argoInstanceName', async (request, response) => {
const argoInstanceName = request.params.argoInstanceName;
const matchedArgoInstance = findArgoInstance(argoInstanceName);
if (matchedArgoInstance === undefined) {
Expand All @@ -65,39 +65,51 @@ export function createRouter({
message: 'could not generate token',
});
}
return response.send(await argoSvc.getArgoAppData(
matchedArgoInstance.url,
matchedArgoInstance.name,
token
))
})

router.get('/argoInstance/:argoInstance/repo/:repo/source/:source', async(request, response) => {
const argoInstanceName = request.params.argoInstance;
const matchedArgoInstance = findArgoInstance(argoInstanceName);
if (matchedArgoInstance === undefined) {
return response.status(500).send({
status: 'failed',
message: 'cannot find an argo instance to match this cluster',
});
}
const token: string = await findMatchedArgoInstanceToken(
matchedArgoInstance,
return response.send(
await argoSvc.getArgoAppData(
matchedArgoInstance.url,
matchedArgoInstance.name,
token,
),
);
if (!token) {
return response.status(500).send({
status: 'failed',
message: 'could not generate token',
});
}
const argoData = await argoSvc.getArgoAppData(
matchedArgoInstance.url,
matchedArgoInstance.name,
token
)
const repoAndSource = argoData.items.map((argoApp: any) => `${argoApp?.spec?.source?.repoURL}/${argoApp?.spec?.source?.path}`)
return response.send(repoAndSource.includes(`${request.params.repo}/${decodeURIComponent(request.params.source)}`))
})
});

router.get(
'/argoInstance/:argoInstance/repo/:repo/source/:source',
async (request, response) => {
const argoInstanceName = request.params.argoInstance;
const matchedArgoInstance = findArgoInstance(argoInstanceName);
if (matchedArgoInstance === undefined) {
return response.status(500).send({
status: 'failed',
message: 'cannot find an argo instance to match this cluster',
});
}
const token: string = await findMatchedArgoInstanceToken(
matchedArgoInstance,
);
if (!token) {
return response.status(500).send({
status: 'failed',
message: 'could not generate token',
});
}
const argoData = await argoSvc.getArgoAppData(
matchedArgoInstance.url,
matchedArgoInstance.name,
token,
);
const repoAndSource = argoData.items.map(
(argoApp: any) =>
`${argoApp?.spec?.source?.repoURL}/${argoApp?.spec?.source?.path}`,
);
return response.send(
repoAndSource.includes(
`${request.params.repo}/${decodeURIComponent(request.params.source)}`,
),
);
},
);

router.get('/find/name/:argoAppName', async (request, response) => {
const argoAppName = request.params.argoAppName;
Expand Down Expand Up @@ -153,7 +165,7 @@ export function createRouter({
matchedArgoInstance.url,
matchedArgoInstance.name,
token,
{ name: argoAppName }
{ name: argoAppName },
);
return response.send(resp);
},
Expand Down Expand Up @@ -184,7 +196,7 @@ export function createRouter({
matchedArgoInstance.url,
matchedArgoInstance.name,
token,
{ selector: argoAppSelector }
{ selector: argoAppSelector },
);
return response.send(resp);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export interface ArgoServiceApi {
name: string;
selector: string;
},

) => Promise<object>;
createArgoProject: (props: CreateArgoProjectProps) => Promise<object>;
createArgoApplication: (props: CreateArgoApplicationProps) => Promise<object>;
Expand Down

0 comments on commit d00ea30

Please sign in to comment.