Skip to content

Commit dc9a853

Browse files
committed
test(llmo): cover rescanCdnLogDelivery branches for codecov/patch (LLMO-5566)
- Remove dead !Organization early-return from gateEdgeOptimizeWizard - Add test for custom EDGE_OPTIMIZE_ROLE_NAME env var path - Add test for rejection with no .message (covers 'unknown error' fallback) Introduced by: #2680
1 parent b13f3ed commit dc9a853

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/controllers/llmo/llmo.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,7 +2349,7 @@ function LlmoController(ctx) {
23492349
// must have access to the site and be an LLMO administrator. Returns { error } (a Response)
23502350
// when denied, or { site, imsOrgId, externalId } when allowed. Pass Organization to also
23512351
// derive the org-scoped ExternalId used by assumeConnectorRole.
2352-
const gateEdgeOptimizeWizard = async (siteId, Site, action, Organization = null) => {
2352+
const gateEdgeOptimizeWizard = async (siteId, Site, action, Organization) => {
23532353
const site = await Site.findById(siteId);
23542354
if (!site) {
23552355
return { error: notFound('Site not found') };
@@ -2360,9 +2360,6 @@ function LlmoController(ctx) {
23602360
if (!accessControlUtil.isLLMOAdministrator()) {
23612361
return { error: forbidden(`Only LLMO administrators can ${action}`) };
23622362
}
2363-
if (!Organization) {
2364-
return { site };
2365-
}
23662363
const organization = await Organization.findById(site.getOrganizationId());
23672364
const imsOrgId = organization?.getImsOrgId();
23682365
if (!hasText(imsOrgId)) {

test/controllers/llmo/llmo.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8149,6 +8149,30 @@ describe('LlmoController', () => {
81498149
expect(body.distributions[1].error).to.equal('AccessDenied');
81508150
});
81518151

8152+
it('uses a custom role name when EDGE_OPTIMIZE_ROLE_NAME is set', async () => {
8153+
const ctx = {
8154+
...rescanContext,
8155+
env: { ...rescanContext.env, EDGE_OPTIMIZE_ROLE_NAME: 'CustomConnectorRole' },
8156+
};
8157+
8158+
const result = await controller.rescanCdnLogDelivery(ctx);
8159+
8160+
expect(result.status).to.equal(200);
8161+
const callArgs = assumeConnectorRoleStub.firstCall.args[0];
8162+
expect(callArgs.roleName).to.equal('CustomConnectorRole');
8163+
});
8164+
8165+
it('falls back to "unknown error" when a rejection has no message', async () => {
8166+
createCdnLogDeliveryStub.onFirstCall().resolves({ created: true, alreadyExisted: false });
8167+
createCdnLogDeliveryStub.onSecondCall().rejects('non-error rejection');
8168+
8169+
const result = await controller.rescanCdnLogDelivery(rescanContext);
8170+
8171+
expect(result.status).to.equal(200);
8172+
const body = await result.json();
8173+
expect(body.distributions[1].error).to.equal('unknown error');
8174+
});
8175+
81528176
it('returns 400 for an invalid account id', async () => {
81538177
const result = await controller.rescanCdnLogDelivery({
81548178
...rescanContext,

0 commit comments

Comments
 (0)