Repository navigation
test: add unit tests for authorization, boot, booter-lb3app, context, express, core and metadata - #11854
Open
pranesh-sridhar wants to merge 6 commits into
Open
test: add unit tests for authorization, boot, booter-lb3app, context, express, core and metadata#11854pranesh-sridhar wants to merge 6 commits into
pranesh-sridhar wants to merge 6 commits into
Conversation
- Interceptor: invoke voter functions declared directly in the @authorize metadata, for both allow and deny decisions - @authorize: throws when applied to a property Statement, function and line coverage of the package is now 100%. Signed-off-by: Pranesh Sridhar <68075088+pranesh-sridhar@users.noreply.github.com>
…configure Cover the guard for applications without mountExpressRouter, option merging with defaults, and appPath resolution. Signed-off-by: Pranesh Sridhar <68075088+pranesh-sridhar@users.noreply.github.com>
…ixin bindings - ModelBooter: default and custom options, binding of model classes - ModelApiBooter: getApiBuilderForPattern lookup and error messages - BaseArtifactBooter: artifactName, empty dirs/extensions, discover with and without debug logging - Bootstrapper: reuse booter instances when a context is passed to boot() - BootMixin: PROJECT_ROOT and BOOT_OPTIONS dynamic bindings Signed-off-by: Pranesh Sridhar <68075088+pranesh-sridhar@users.noreply.github.com>
…tion and interceptors Add unit tests for code paths that were not covered by the existing suites: - Binding: refresh without cache, unconfigured bindings, server scope resolution failures, once() - ContextView: singleValue(), open() reuse, once() - Context: findByTag with unknown or intersecting tags, observer subscribe/unsubscribe/close edge cases - Injection: hasInjections, inspectInjections, @inject.setter and @inject.binding rejecting binding filters, @config.getter/@config.view without a current binding - Interceptors: stacked @intercept on classes and methods, registering provider classes and grouped global interceptors, interception proxy - InvocationContext.toString(), invokeMethod with skipInterceptors, BindingKey.validate, isBindingAddress, uuid Signed-off-by: Pranesh Sridhar <68075088+pranesh-sridhar@users.noreply.github.com>
…d invoke provider - ExpressServer: basePath normalization, Express settings, listening and url lifecycle, serving under basePath, parent context - toMiddleware and invokeExpressMiddleware: single/chained handlers and the empty-handler error - getMiddlewareContext: missing request and bound context - MiddlewareMixin: non-Context super class and empty handler list - MiddlewareView: group ordering, refresh, validate callback, debug logging - InvokeMiddlewareProvider: handler arrays, default and custom chains - sortListOfGroups: debug logging and short group lists Signed-off-by: Pranesh Sridhar <68075088+pranesh-sridhar@users.noreply.github.com>
pranesh-sridhar
requested review from
nabdelgadir and
raymondfeng
as code owners
October 22, 2026 08:25
Add unit tests to cover code paths in `@loopback/core` and `@loopback/metadata` that the existing suites did not exercise. Coverage was measured with `nyc` over each package's `dist/` output. Only test files are changed; there are no source changes. `@loopback/authentication` is covered in loopbackio#11853. `@loopback/authorization`, `boot`, `booter-lb3app`, `context`, and `express` are covered in loopbackio#11854. | Package | Tests before | Tests after | Stmts before | Stmts after | |---|---|---|---|---| | `core` | 346 | 355 | 95.47% | 98.74% | | `metadata` | 162 | 171 | 96.18% | 98.09% | ### Tests added **`@loopback/core`** - `application-lifecycle.unit.ts`: `assertInStates()` — throws when the application is not in the expected state; does not throw when it is - `application.unit.ts`: `setMetadata()` — stores metadata under `CoreBindings.APPLICATION_METADATA`; overwrites on a second call - `component.unit.ts`: `mountComponent()` self-reference guard — skips a component instance placed directly in its own `components` array - `lifecycle-registry.unit.ts`: `getObserverGroupsByOrder()` — debug logging branch exercised by enabling the `loopback:core:lifecycle` namespace temporarily - `service.unit.ts`: `@service()` without design-time type metadata — throws "No design-time type metadata found" when `design:type` is absent; `createServiceBinding()` with a `DynamicValueProvider` class — trims the `Provider` suffix from the name; preserves a custom name **`@loopback/metadata`** - `decorator-factory.unit.ts`: Base-class abstract-method guards — `mergeWithInherited()`, `mergeWithOwn()`, and `create()` each throw "not implemented" when the subclass does not override them; `getTarget()` returns `undefined` for non-object specs; `MethodMultiDecoratorFactory` `mergeWithOwn` exercised on a standalone class with no base - `inspector.unit.ts`: `MetadataInspector.defineMetadata()` — stores and overwrites class-level metadata; `getMethodMetadata()` with `methodName` omitted defaults to the constructor key ### Verification All tests pass (`npm test` per package, `lb-tsc` build + `lb-mocha`). ESLint (`--report-unused-disable-directives`) and Prettier clean on all changed files. Signed-off-by: Pranesh Sridhar <Pranesh.Sridhar@ibm.com>
dhmlau
approved these changes
Oct 25, 2026
dhmlau
left a comment
Member
There was a problem hiding this comment.
@pranesh-sridhar, thanks for your PR. Your PR LGTM.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add unit tests to cover code paths in five core packages and two additional packages that the existing suites did not exercise. Gaps were identified from measured
nyccoverage of each package'sdist/output. Only test files are changed; there are no source changes.@loopback/authenticationis covered separately in #11853.authorizationbooter-lb3appbootsrc/gaps closed exceptmodel.booter.ts52-53contextexpresscoremetadataNote on
boot: the baseline report also counted compiled fixtures underdist/, so a single before/after percentage is not comparable. The uncoveredsrc/lines it reported are now covered, apart from themodel.booter.tslines noted above.Tests added
authorization: voter functions declared in@authorizemetadata (allow and deny);@authorizeon a property throwsbooter-lb3app:Lb3AppBooterconstructor guard, option merging,configure()path resolutionboot:ModelBooter,ModelApiBooter.getApiBuilderForPattern,BaseArtifactBooter(artifactName, empty options,discoverwith and without debug logging),Bootstrappercontext reuse,BootMixinbindingscontext: binding/view/subscription edge cases,findByTagwith unknown or intersecting tags,hasInjections,inspectInjections,@inject.setter/@inject.bindingrejecting filters,@config.getter/@config.view, stacked@intercept, interception proxy,invokeMethodwithskipInterceptorsexpress:ExpressServer(basePath, settings, start/stop, url),toMiddleware,invokeExpressMiddleware,getMiddlewareContext,MiddlewareMixinguards,MiddlewareView,InvokeMiddlewareProvider,sortListOfGroupscore:assertInStates()— throws when the application is not in the expected state;setMetadata()— stores and overwritesCoreBindings.APPLICATION_METADATA;mountComponent()self-reference guard;getObserverGroupsByOrder()debug-logging branch;@service()without design-time type metadata;createServiceBinding()with aDynamicValueProviderclassmetadata: base-class abstract-method guards (mergeWithInherited(),mergeWithOwn(),create());getTarget()returningundefinedfor non-object specs;MethodMultiDecoratorFactory.mergeWithOwnon a standalone class;MetadataInspector.defineMetadata();getMethodMetadata()withmethodNameomittedVerification
Run locally on this branch, per package (
lb-tscbuild, thenlb-mocha): all passing, 0 failing. ESLint (--report-unused-disable-directives) and Prettier are clean on all changed files.Remaining uncovered code is mostly defensive or compiler-generated, for example the
namespacemerge blocks and debug-only logging.Checklist
npm testpasses on your machine (ran each affected package's build and tests, plus lint on changed files; full monoreponpm testnot run)packages/cliwere updated (n/a)examples/*were updated (n/a)