|
1 | 1 | import {createOpenApiRegistry} from '../openapi-registry'; |
2 | 2 | import {apiKeyAuth, bearerAuth} from '../security-schemas'; |
3 | | -import {AppRoutes, AuthPolicy, RouteContract, withContract} from '@gravity-ui/expresskit'; |
| 3 | +import { |
| 4 | + AppMountDescription, |
| 5 | + AppRoutes, |
| 6 | + AuthPolicy, |
| 7 | + RouteContract, |
| 8 | + withContract, |
| 9 | +} from '@gravity-ui/expresskit'; |
4 | 10 | import {NodeKit} from '@gravity-ui/nodekit'; |
5 | 11 | import {z} from 'zod'; |
6 | 12 |
|
@@ -669,6 +675,33 @@ describe('openapi-registry', () => { |
669 | 675 |
|
670 | 676 | const registeredRoutes = registerRoutes(routes, nodekit); |
671 | 677 | expect(registeredRoutes).toHaveProperty('MOUNT /api/docs'); |
| 678 | + const mountRoute = registeredRoutes['MOUNT /api/docs'] as AppMountDescription; |
| 679 | + expect(mountRoute).toBeDefined(); |
| 680 | + expect(mountRoute.authPolicy).toBe(AuthPolicy.disabled); |
| 681 | + }); |
| 682 | + |
| 683 | + it('should apply configured authPolicy to MOUNT route', () => { |
| 684 | + const {registerRoutes} = createOpenApiRegistry({ |
| 685 | + title: 'Test API', |
| 686 | + authPolicy: AuthPolicy.required, |
| 687 | + }); |
| 688 | + |
| 689 | + const routes = { |
| 690 | + 'GET /test': { |
| 691 | + handler: withContract({ |
| 692 | + request: {}, |
| 693 | + response: {content: {200: z.object({})}}, |
| 694 | + })(async (_req, res) => { |
| 695 | + res.sendTyped(200, {}); |
| 696 | + }), |
| 697 | + }, |
| 698 | + }; |
| 699 | + |
| 700 | + const registeredRoutes = registerRoutes(routes, nodekit); |
| 701 | + const mountRoute = registeredRoutes['MOUNT /api/docs'] as AppMountDescription; |
| 702 | + |
| 703 | + expect(mountRoute).toBeDefined(); |
| 704 | + expect(mountRoute.authPolicy).toBe(AuthPolicy.required); |
672 | 705 | }); |
673 | 706 |
|
674 | 707 | it('should handle routes with tags and description', () => { |
|
0 commit comments