Best JavaScript code snippet using storybook-root
decorators.spec.ts
Source:decorators.spec.ts
1// std2import { deepStrictEqual, strictEqual } from 'assert';3// FoalTS4import { getMetadata } from '../routes/utils';5import {6 ApiCallback, ApiDefineCallback, ApiDefineExample, ApiDefineHeader,7 ApiDefineLink, ApiDefineParameter, ApiDefineRequestBody, ApiDefineResponse,8 ApiDefineSchema, ApiDefineSecurityScheme, ApiDefineTag, ApiDeprecated,9 ApiExternalDoc, ApiInfo, ApiOperation, ApiOperationDescription, ApiOperationId,10 ApiOperationSummary, ApiParameter, ApiRequestBody, ApiResponse, ApiSecurityRequirement, ApiServer, ApiUseTag11} from './decorators';12import {13 IApiCallback, IApiExample, IApiExternalDocumentation,14 IApiHeader, IApiInfo, IApiLink, IApiOperation, IApiParameter,15 IApiRequestBody, IApiResponse, IApiSchema, IApiSecurityRequirement,16 IApiSecurityScheme, IApiServer, IApiTag17} from './interfaces';18describe('ApiInfo', () => {19 it('should define the correct metadata.', () => {20 const metadata: IApiInfo = {21 contact: {22 email: 'support@example.com',23 name: 'API Support',24 url: 'http://www.example.com/support',25 },26 description: 'This is a sample server for a pet store.',27 license: {28 name: 'Apache 2.0',29 url: 'http://www.apache.org/licenses/LICENSE-2.0.html'30 },31 termsOfService: 'http://example.com/terms/',32 title: 'Sample Pet Store App',33 version: '1.0.1'34 };35 @ApiInfo(metadata)36 class Controller { }37 strictEqual(getMetadata('api:document:info', Controller), metadata);38 });39 it('should define the correct metadata (dynamic).', () => {40 const metadata: IApiInfo = {41 contact: {42 email: 'support@example.com',43 name: 'API Support',44 url: 'http://www.example.com/support',45 },46 description: 'This is a sample server for a pet store.',47 license: {48 name: 'Apache 2.0',49 url: 'http://www.apache.org/licenses/LICENSE-2.0.html'50 },51 termsOfService: 'http://example.com/terms/',52 title: 'Sample Pet Store App',53 version: '1.0.1'54 };55 const metadataFunc = (controller: any) => metadata;56 @ApiInfo(metadataFunc)57 class Controller { }58 strictEqual(getMetadata('api:document:info', Controller), metadataFunc);59 });60});61describe('ApiOperationDescription', () => {62 const metadata: string = 'Returns pets based on ID';63 it('should define the correct metadata (method).', () => {64 class Controller {65 @ApiOperationDescription(metadata)66 foo() { }67 }68 deepStrictEqual(getMetadata('api:operation:description', Controller, 'foo'), 'Returns pets based on ID');69 });70 it('should define the correct metadata (method & dynamic).', () => {71 const metadataFunc = (controller: any) => metadata;72 class Controller {73 @ApiOperationDescription(metadataFunc)74 foo() { }75 }76 deepStrictEqual(getMetadata('api:operation:description', Controller, 'foo'), metadataFunc);77 });78});79describe('ApiOperationId', () => {80 const metadata: string = 'updatePet';81 it('should define the correct metadata (method).', () => {82 class Controller {83 @ApiOperationId(metadata)84 foo() { }85 }86 deepStrictEqual(getMetadata('api:operation:operationId', Controller, 'foo'), 'updatePet');87 });88 it('should define the correct metadata (method & dynamic).', () => {89 const metadataFunc = (controller: any) => metadata;90 class Controller {91 @ApiOperationId(metadataFunc)92 foo() { }93 }94 deepStrictEqual(getMetadata('api:operation:operationId', Controller, 'foo'), metadataFunc);95 });96});97describe('ApiOperationSummary', () => {98 const metadata: string = 'Find pets by ID';99 it('should define the correct metadata (method).', () => {100 class Controller {101 @ApiOperationSummary(metadata)102 foo() { }103 }104 deepStrictEqual(getMetadata('api:operation:summary', Controller, 'foo'), 'Find pets by ID');105 });106 it('should define the correct metadata (method & dynamic).', () => {107 const metadataFunc = (controller: any) => metadata;108 class Controller {109 @ApiOperationSummary(metadataFunc)110 foo() { }111 }112 deepStrictEqual(getMetadata('api:operation:summary', Controller, 'foo'), metadataFunc);113 });114});115describe('ApiServer', () => {116 const metadata: IApiServer = {117 description: 'Development server',118 url: 'https://development.gigantic-server.com/v1',119 };120 const metadata2: IApiServer = {121 description: 'Staging server',122 url: 'https://staging.gigantic-server.com/v1',123 };124 it('should define the correct metadata (class).', () => {125 @ApiServer(metadata)126 class Controller { }127 deepStrictEqual(getMetadata('api:documentOrOperation:servers', Controller), [metadata]);128 @ApiServer(metadata)129 @ApiServer(metadata2)130 class Controller2 { }131 deepStrictEqual(getMetadata('api:documentOrOperation:servers', Controller2), [metadata, metadata2]);132 });133 it('should define the correct metadata (class & dynamic).', () => {134 const metadataFunc = (controller: any) => metadata;135 @ApiServer(metadataFunc)136 class Controller { }137 deepStrictEqual(getMetadata('api:documentOrOperation:servers', Controller), [metadataFunc]);138 });139 it('should define the correct metadata (class & inheritance).', () => {140 @ApiServer(metadata)141 class Controller { }142 deepStrictEqual(getMetadata('api:documentOrOperation:servers', Controller), [metadata]);143 @ApiServer(metadata2)144 class Controller2 extends Controller { }145 deepStrictEqual(getMetadata('api:documentOrOperation:servers', Controller), [metadata]);146 deepStrictEqual(getMetadata('api:documentOrOperation:servers', Controller2), [metadata2, metadata]);147 });148 it('should define the correct metadata (method).', () => {149 class Controller {150 @ApiServer(metadata)151 foo() { }152 }153 deepStrictEqual(getMetadata('api:documentOrOperation:servers', Controller, 'foo'), [metadata]);154 class Controller2 {155 @ApiServer(metadata)156 @ApiServer(metadata2)157 foo() { }158 }159 deepStrictEqual(getMetadata('api:documentOrOperation:servers', Controller2, 'foo'), [metadata, metadata2]);160 });161});162describe('ApiSecurityRequirement', () => {163 const metadata: IApiSecurityRequirement = {164 api_key: []165 };166 const metadata2: IApiSecurityRequirement = {167 petstore_auth: [168 'write:pets',169 'read:pets'170 ]171 };172 it('should define the correct metadata (class).', () => {173 @ApiSecurityRequirement(metadata)174 class Controller { }175 deepStrictEqual(getMetadata('api:documentOrOperation:security', Controller), [metadata]);176 @ApiSecurityRequirement(metadata)177 @ApiSecurityRequirement(metadata2)178 class Controller2 { }179 deepStrictEqual(getMetadata('api:documentOrOperation:security', Controller2), [metadata, metadata2]);180 });181 it('should define the correct metadata (class & dynamic).', () => {182 const metadataFunc = (controller: any) => metadata;183 @ApiSecurityRequirement(metadataFunc)184 class Controller { }185 deepStrictEqual(getMetadata('api:documentOrOperation:security', Controller), [metadataFunc]);186 });187 it('should define the correct metadata (method).', () => {188 class Controller {189 @ApiSecurityRequirement(metadata)190 foo() { }191 }192 deepStrictEqual(getMetadata('api:documentOrOperation:security', Controller, 'foo'), [metadata]);193 class Controller2 {194 @ApiSecurityRequirement(metadata)195 @ApiSecurityRequirement(metadata2)196 foo() { }197 }198 deepStrictEqual(getMetadata('api:documentOrOperation:security', Controller2, 'foo'), [metadata, metadata2]);199 });200});201describe('ApiDefineTag', () => {202 const metadata: IApiTag = {203 description: 'Pets operations',204 name: 'pet',205 };206 const metadata2: IApiTag = {207 description: 'Pets operations',208 name: 'pet2',209 };210 it('should define the correct metadata (class).', () => {211 @ApiDefineTag(metadata)212 class Controller { }213 deepStrictEqual(getMetadata('api:document:tags', Controller), [metadata]);214 @ApiDefineTag(metadata)215 @ApiDefineTag(metadata2)216 class Controller2 { }217 deepStrictEqual(getMetadata('api:document:tags', Controller2), [metadata, metadata2]);218 });219 it('should define the correct metadata (class & dynamic).', () => {220 const metadataFunc = (controller: any) => metadata;221 @ApiDefineTag(metadataFunc)222 class Controller { }223 deepStrictEqual(getMetadata('api:document:tags', Controller), [metadataFunc]);224 });225 it('should define the correct metadata (method).', () => {226 class Controller {227 @ApiDefineTag(metadata)228 foo() { }229 }230 deepStrictEqual(getMetadata('api:document:tags', Controller, 'foo'), [metadata]);231 class Controller2 {232 @ApiDefineTag(metadata)233 @ApiDefineTag(metadata2)234 foo() { }235 }236 deepStrictEqual(getMetadata('api:document:tags', Controller2, 'foo'), [metadata, metadata2]);237 });238});239describe('ApiExternalDoc', () => {240 const metadata: IApiExternalDocumentation = {241 description: 'Find more info here',242 url: 'https://example.com',243 };244 it('should define the correct metadata (class).', () => {245 @ApiExternalDoc(metadata)246 class Controller { }247 strictEqual(getMetadata('api:documentOrOperation:externalDocs', Controller), metadata);248 });249 it('should define the correct metadata (class & dynamic).', () => {250 const metadataFunc = (controller: any) => metadata;251 @ApiExternalDoc(metadataFunc)252 class Controller { }253 strictEqual(getMetadata('api:documentOrOperation:externalDocs', Controller), metadataFunc);254 });255 it('should define the correct metadata (method).', () => {256 class Controller {257 @ApiExternalDoc(metadata)258 foo() { }259 }260 strictEqual(getMetadata('api:documentOrOperation:externalDocs', Controller, 'foo'), metadata);261 });262});263describe('ApiOperation', () => {264 const metadata: IApiOperation = {265 operationId: 'updatePetWithForm',266 parameters: [267 {268 description: 'ID of pet that needs to be updated',269 in: 'path',270 name: 'petId',271 required: true,272 schema: {273 type: 'string'274 }275 }276 ],277 requestBody: {278 content: {279 'application/x-www-form-urlencoded': {280 schema: {281 properties: {282 name: {283 description: 'Updated name of the pet',284 type: 'string'285 },286 status: {287 description: 'Updated status of the pet',288 type: 'string'289 }290 },291 required: ['status'],292 type: 'object',293 }294 }295 }296 },297 responses: {298 200: {299 content: {300 'application/json': {},301 'application/xml': {}302 },303 description: 'Pet updated.',304 },305 405: {306 content: {307 'application/json': {},308 'application/xml': {}309 },310 description: 'Method Not Allowed',311 }312 },313 security: [314 {315 petstore_auth: [316 'write:pets',317 'read:pets'318 ]319 }320 ],321 summary: 'Updates a pet in the store with form data',322 tags: [323 'pet'324 ],325 };326 it('should define the correct metadata (method).', () => {327 class Controller {328 @ApiOperation(metadata)329 foo() { }330 }331 strictEqual(getMetadata('api:operation', Controller, 'foo'), metadata);332 });333 it('should define the correct metadata (method & dynamic).', () => {334 const metadataFunc = (controller: any) => metadata;335 class Controller {336 @ApiOperation(metadataFunc)337 foo() { }338 }339 strictEqual(getMetadata('api:operation', Controller, 'foo'), metadataFunc);340 });341});342describe('ApiUseTag', () => {343 const metadata: string = 'tag1';344 const metadata2: string = 'tag2';345 it('should define the correct metadata (class).', () => {346 @ApiUseTag(metadata)347 class Controller { }348 deepStrictEqual(getMetadata('api:operation:tags', Controller), [metadata]);349 @ApiUseTag(metadata)350 @ApiUseTag(metadata2)351 class Controller2 { }352 deepStrictEqual(getMetadata('api:operation:tags', Controller2), [metadata, metadata2]);353 });354 it('should define the correct metadata (class).', () => {355 const metadataFunc = (controller: any) => metadata;356 @ApiUseTag(metadataFunc)357 class Controller { }358 deepStrictEqual(getMetadata('api:operation:tags', Controller), [metadataFunc]);359 });360 it('should define the correct metadata (method).', () => {361 class Controller {362 @ApiUseTag(metadata)363 foo() { }364 }365 deepStrictEqual(getMetadata('api:operation:tags', Controller, 'foo'), [metadata]);366 class Controller2 {367 @ApiUseTag(metadata)368 @ApiUseTag(metadata2)369 foo() { }370 }371 deepStrictEqual(getMetadata('api:operation:tags', Controller2, 'foo'), [metadata, metadata2]);372 });373});374describe('ApiParameter', () => {375 const metadata: IApiParameter = {376 description: 'ID of pet that needs to be updated',377 in: 'path',378 name: 'petId',379 required: true,380 schema: {381 type: 'string'382 }383 };384 const metadata2: IApiParameter = {385 description: 'token to be passed as a header',386 in: 'header',387 name: 'token',388 required: true,389 schema: {390 items: {391 format: 'int64',392 type: 'integer',393 },394 type: 'array',395 },396 style: 'simple'397 };398 it('should define the correct metadata (class).', () => {399 @ApiParameter(metadata)400 class Controller { }401 deepStrictEqual(getMetadata('api:operation:parameters', Controller), [metadata]);402 @ApiParameter(metadata)403 @ApiParameter(metadata2)404 class Controller2 { }405 deepStrictEqual(getMetadata('api:operation:parameters', Controller2), [metadata, metadata2]);406 });407 it('should define the correct metadata (class & dynamic).', () => {408 const metadataFunc = (controller: any) => metadata;409 @ApiParameter(metadataFunc)410 class Controller { }411 deepStrictEqual(getMetadata('api:operation:parameters', Controller), [metadataFunc]);412 });413 it('should define the correct metadata (method).', () => {414 class Controller {415 @ApiParameter(metadata)416 foo() { }417 }418 deepStrictEqual(getMetadata('api:operation:parameters', Controller, 'foo'), [metadata]);419 class Controller2 {420 @ApiParameter(metadata)421 @ApiParameter(metadata2)422 foo() { }423 }424 deepStrictEqual(getMetadata('api:operation:parameters', Controller2, 'foo'), [metadata, metadata2]);425 });426});427describe('ApiRequestBody', () => {428 const metadata: IApiRequestBody = {429 content: {430 '*/*': {431 examples: {432 user : {433 externalValue: 'http://foo.bar/examples/user-example.whatever',434 summary: 'User example in other format',435 }436 }437 },438 'application/json': {439 examples: {440 user : {441 externalValue: 'http://foo.bar/examples/user-example.json',442 summary: 'User Example',443 }444 },445 schema: {446 $ref: '#/components/schemas/User'447 },448 },449 'application/xml': {450 examples: {451 user : {452 externalValue: 'http://foo.bar/examples/user-example.xml',453 summary: 'User example in XML',454 }455 },456 schema: {457 $ref: '#/components/schemas/User'458 },459 },460 'text/plain': {461 examples: {462 user : {463 externalValue: 'http://foo.bar/examples/user-example.txt',464 summary: 'User example in Plain text',465 }466 }467 },468 },469 description: 'user to add to the system',470 };471 it('should define the correct metadata (method).', () => {472 class Controller {473 @ApiRequestBody(metadata)474 foo() { }475 }476 strictEqual(getMetadata('api:operation:requestBody', Controller, 'foo'), metadata);477 });478 it('should define the correct metadata (method & dynamic metadata).', () => {479 const metadataFunc = (controller: any) => metadata;480 class Controller {481 @ApiRequestBody(metadataFunc)482 foo() { }483 }484 strictEqual(getMetadata('api:operation:requestBody', Controller, 'foo'), metadataFunc);485 });486});487describe('ApiResponse', () => {488 const metadata: IApiResponse = {489 content: {490 'application/json': {491 schema: {492 $ref: '#/components/schemas/GeneralError'493 }494 }495 },496 description: 'General Error',497 };498 const metadata2: IApiResponse = {499 description: 'Entity not found.'500 };501 it('should define the correct metadata (class).', () => {502 @ApiResponse('default', metadata)503 @ApiResponse(404, metadata2)504 class Controller {}505 deepStrictEqual(getMetadata('api:operation:responses', Controller), {506 default: metadata,507 404: metadata2508 });509 });510 it('should define the correct metadata (class & dynamic).', () => {511 const metadataFunc = (controller: any) => metadata;512 @ApiResponse('default', metadataFunc)513 class Controller {}514 deepStrictEqual(getMetadata('api:operation:responses', Controller), {515 default: metadataFunc,516 });517 });518 it('should define the correct metadata (class & inheritance).', () => {519 @ApiResponse('default', metadata)520 class Controller {}521 deepStrictEqual(getMetadata('api:operation:responses', Controller), {522 default: metadata,523 });524 @ApiResponse(404, metadata2)525 class Controller2 extends Controller {}526 deepStrictEqual(getMetadata('api:operation:responses', Controller), {527 default: metadata528 });529 deepStrictEqual(getMetadata('api:operation:responses', Controller2), {530 default: metadata,531 404: metadata2532 });533 });534 it('should define the correct metadata (method).', () => {535 class Controller {536 @ApiResponse('default', metadata)537 @ApiResponse(404, metadata2)538 foo() { }539 }540 deepStrictEqual(getMetadata('api:operation:responses', Controller, 'foo'), {541 default: metadata,542 404: metadata2543 });544 });545});546describe('ApiCallback', () => {547 const metadata: IApiCallback = {};548 const metadata2: IApiCallback = {};549 it('should define the correct metadata (class).', () => {550 @ApiCallback('callback1', metadata)551 @ApiCallback('callback2', metadata2)552 class Controller {}553 deepStrictEqual(getMetadata('api:operation:callbacks', Controller), {554 callback1: metadata,555 callback2: metadata2556 });557 });558 it('should define the correct metadata (class & dynamic).', () => {559 const metadataFunc = (controller: any) => metadata;560 @ApiCallback('callback1', metadataFunc)561 class Controller {}562 deepStrictEqual(getMetadata('api:operation:callbacks', Controller), {563 callback1: metadataFunc,564 });565 });566 it('should define the correct metadata (method).', () => {567 class Controller {568 @ApiCallback('callback1', metadata)569 @ApiCallback('callback2', metadata2)570 foo() { }571 }572 deepStrictEqual(getMetadata('api:operation:callbacks', Controller, 'foo'), {573 callback1: metadata,574 callback2: metadata2575 });576 });577});578describe('ApiDeprecated', () => {579 const metadata: boolean = true;580 it('should define the correct metadata (class).', () => {581 @ApiDeprecated(metadata)582 class Controller {}583 strictEqual(getMetadata('api:operation:deprecated', Controller), metadata);584 });585 it('should define the correct metadata (class & dynamic).', () => {586 const metadataFunc = (controller: any) => metadata;587 @ApiDeprecated(metadataFunc)588 class Controller {}589 strictEqual(getMetadata('api:operation:deprecated', Controller), metadataFunc);590 });591 it('should define the correct metadata (method).', () => {592 class Controller {593 @ApiDeprecated(metadata)594 foo() { }595 }596 strictEqual(getMetadata('api:operation:deprecated', Controller, 'foo'), metadata);597 });598});599/* Components */600describe('ApiDefineSchema', () => {601 const metadata: IApiSchema = {602 properties: {603 address: {604 $ref: '#/components/schemas/Address'605 },606 name: {607 type: 'string'608 }609 },610 required: [611 'name'612 ],613 type: 'object',614 };615 const metadata2: IApiSchema = {};616 it('should define the correct metadata (class).', () => {617 @ApiDefineSchema('schema1', metadata)618 @ApiDefineSchema('schema2', metadata2)619 class Controller {}620 deepStrictEqual(getMetadata('api:components:schemas', Controller), {621 schema1: metadata,622 schema2: metadata2623 });624 });625 it('should define the correct metadata (class & dynamic).', () => {626 const metadataFunc = (controller: any) => metadata;627 @ApiDefineSchema('schema1', metadataFunc)628 class Controller {}629 deepStrictEqual(getMetadata('api:components:schemas', Controller), {630 schema1: metadataFunc,631 });632 });633 it('should define the correct metadata (method).', () => {634 class Controller {635 @ApiDefineSchema('schema1', metadata)636 @ApiDefineSchema('schema2', metadata2)637 foo() { }638 }639 deepStrictEqual(getMetadata('api:components:schemas', Controller, 'foo'), {640 schema1: metadata,641 schema2: metadata2642 });643 });644});645describe('ApiDefineResponse', () => {646 const metadata: IApiResponse = {647 content: {648 'application/json': {649 schema: {650 items: {651 $ref: '#/components/schemas/VeryComplexType'652 },653 type: 'array',654 }655 }656 },657 description: 'A complex object array response',658 };659 const metadata2: IApiResponse = {660 content: {661 'text/plain': {662 schema: {663 type: 'string'664 }665 }666 },667 description: 'A simple string response',668 };669 it('should define the correct metadata (class).', () => {670 @ApiDefineResponse('response1', metadata)671 @ApiDefineResponse('response2', metadata2)672 class Controller {}673 deepStrictEqual(getMetadata('api:components:responses', Controller), {674 response1: metadata,675 response2: metadata2676 });677 });678 it('should define the correct metadata (class & dynamic).', () => {679 const metadataFunc = (controller: any) => metadata;680 @ApiDefineResponse('response1', metadataFunc)681 class Controller {}682 deepStrictEqual(getMetadata('api:components:responses', Controller), {683 response1: metadataFunc,684 });685 });686 it('should define the correct metadata (method).', () => {687 class Controller {688 @ApiDefineResponse('response1', metadata)689 @ApiDefineResponse('response2', metadata2)690 foo() { }691 }692 deepStrictEqual(getMetadata('api:components:responses', Controller, 'foo'), {693 response1: metadata,694 response2: metadata2695 });696 });697});698describe('ApiDefineParameter', () => {699 const metadata: IApiParameter = {700 description: 'token to be passed as a header',701 in: 'header',702 name: 'token',703 required: true,704 schema: {705 items: {706 format: 'int64',707 type: 'integer',708 },709 type: 'array',710 },711 style: 'simple'712 };713 const metadata2: IApiParameter = {714 description: 'username to fetch',715 in: 'path',716 name: 'username',717 required: true,718 schema: {719 type: 'string'720 }721 };722 it('should define the correct metadata (class).', () => {723 @ApiDefineParameter('parameter1', metadata)724 @ApiDefineParameter('parameter2', metadata2)725 class Controller {}726 deepStrictEqual(getMetadata('api:components:parameters', Controller), {727 parameter1: metadata,728 parameter2: metadata2729 });730 });731 it('should define the correct metadata (class).', () => {732 const metadataFunc = (controller: any) => metadata;733 @ApiDefineParameter('parameter1', metadataFunc)734 class Controller {}735 deepStrictEqual(getMetadata('api:components:parameters', Controller), {736 parameter1: metadataFunc,737 });738 });739 it('should define the correct metadata (method).', () => {740 class Controller {741 @ApiDefineParameter('parameter1', metadata)742 @ApiDefineParameter('parameter2', metadata2)743 foo() { }744 }745 deepStrictEqual(getMetadata('api:components:parameters', Controller, 'foo'), {746 parameter1: metadata,747 parameter2: metadata2748 });749 });750});751describe('ApiDefineExample', () => {752 const metadata: IApiExample = {};753 const metadata2: IApiExample = {};754 it('should define the correct metadata (class).', () => {755 @ApiDefineExample('example1', metadata)756 @ApiDefineExample('example2', metadata2)757 class Controller {}758 deepStrictEqual(getMetadata('api:components:examples', Controller), {759 example1: metadata,760 example2: metadata2761 });762 });763 it('should define the correct metadata (class & dynamic).', () => {764 const metadataFunc = (controller: any) => metadata;765 @ApiDefineExample('example1', metadataFunc)766 class Controller {}767 deepStrictEqual(getMetadata('api:components:examples', Controller), {768 example1: metadataFunc,769 });770 });771 it('should define the correct metadata (method).', () => {772 class Controller {773 @ApiDefineExample('example1', metadata)774 @ApiDefineExample('example2', metadata2)775 foo() { }776 }777 deepStrictEqual(getMetadata('api:components:examples', Controller, 'foo'), {778 example1: metadata,779 example2: metadata2780 });781 });782});783describe('ApiDefineRequestBody', () => {784 const metadata: IApiRequestBody = {785 content: {786 '*/*': {787 examples: {788 user : {789 externalValue: 'http://foo.bar/examples/user-example.whatever',790 summary: 'User example in other format',791 }792 }793 },794 'application/json': {795 examples: {796 user : {797 externalValue: 'http://foo.bar/examples/user-example.json',798 summary: 'User Example',799 }800 },801 schema: {802 $ref: '#/components/schemas/User'803 },804 },805 'application/xml': {806 examples: {807 user : {808 externalValue: 'http://foo.bar/examples/user-example.xml',809 summary: 'User example in XML',810 }811 },812 schema: {813 $ref: '#/components/schemas/User'814 },815 },816 'text/plain': {817 examples: {818 user : {819 externalValue: 'http://foo.bar/examples/user-example.txt',820 summary: 'User example in Plain text',821 }822 }823 },824 },825 description: 'user to add to the system',826 };827 const metadata2: IApiRequestBody = {828 content: {829 'text/plain': {830 schema: {831 items: {832 type: 'string'833 },834 type: 'array',835 }836 }837 },838 description: 'user to add to the system',839 };840 it('should define the correct metadata (class).', () => {841 @ApiDefineRequestBody('requestBody1', metadata)842 @ApiDefineRequestBody('requestBody2', metadata2)843 class Controller {}844 deepStrictEqual(getMetadata('api:components:requestBodies', Controller), {845 requestBody1: metadata,846 requestBody2: metadata2847 });848 });849 it('should define the correct metadata (class & dynamic).', () => {850 const metadataFunc = (controller: any) => metadata;851 @ApiDefineRequestBody('requestBody1', metadataFunc)852 class Controller {}853 deepStrictEqual(getMetadata('api:components:requestBodies', Controller), {854 requestBody1: metadataFunc,855 });856 });857 it('should define the correct metadata (method).', () => {858 class Controller {859 @ApiDefineRequestBody('requestBody1', metadata)860 @ApiDefineRequestBody('requestBody2', metadata2)861 foo() { }862 }863 deepStrictEqual(getMetadata('api:components:requestBodies', Controller, 'foo'), {864 requestBody1: metadata,865 requestBody2: metadata2866 });867 });868});869describe('ApiDefineHeader', () => {870 const metadata: IApiHeader = {871 description: 'The number of allowed requests in the current period',872 schema: {873 type: 'integer'874 },875 };876 const metadata2: IApiHeader = {};877 it('should define the correct metadata (class).', () => {878 @ApiDefineHeader('header1', metadata)879 @ApiDefineHeader('header2', metadata2)880 class Controller {}881 deepStrictEqual(getMetadata('api:components:headers', Controller), {882 header1: metadata,883 header2: metadata2884 });885 });886 it('should define the correct metadata (class).', () => {887 const metadataFunc = (controller: any) => metadata;888 @ApiDefineHeader('header1', metadataFunc)889 class Controller {}890 deepStrictEqual(getMetadata('api:components:headers', Controller), {891 header1: metadataFunc,892 });893 });894 it('should define the correct metadata (method).', () => {895 class Controller {896 @ApiDefineHeader('header1', metadata)897 @ApiDefineHeader('header2', metadata2)898 foo() { }899 }900 deepStrictEqual(getMetadata('api:components:headers', Controller, 'foo'), {901 header1: metadata,902 header2: metadata2903 });904 });905});906describe('ApiDefineSecurityScheme', () => {907 const metadata: IApiSecurityScheme = {908 scheme: 'basic',909 type: 'http',910 };911 const metadata2: IApiSecurityScheme = {912 in: 'header',913 name: 'api_key',914 type: 'apiKey',915 };916 it('should define the correct metadata (class).', () => {917 @ApiDefineSecurityScheme('scheme1', metadata)918 @ApiDefineSecurityScheme('scheme2', metadata2)919 class Controller {}920 deepStrictEqual(getMetadata('api:components:securitySchemes', Controller), {921 scheme1: metadata,922 scheme2: metadata2923 });924 });925 it('should define the correct metadata (class).', () => {926 const metadataFunc = (controller: any) => metadata;927 @ApiDefineSecurityScheme('scheme1', metadataFunc)928 class Controller {}929 deepStrictEqual(getMetadata('api:components:securitySchemes', Controller), {930 scheme1: metadataFunc,931 });932 });933 it('should define the correct metadata (method).', () => {934 class Controller {935 @ApiDefineSecurityScheme('scheme1', metadata)936 @ApiDefineSecurityScheme('scheme2', metadata2)937 foo() { }938 }939 deepStrictEqual(getMetadata('api:components:securitySchemes', Controller, 'foo'), {940 scheme1: metadata,941 scheme2: metadata2942 });943 });944});945describe('ApiDefineLink', () => {946 const metadata: IApiLink = {};947 const metadata2: IApiLink = {};948 it('should define the correct metadata (class).', () => {949 @ApiDefineLink('link1', metadata)950 @ApiDefineLink('link2', metadata2)951 class Controller {}952 deepStrictEqual(getMetadata('api:components:links', Controller), {953 link1: metadata,954 link2: metadata2955 });956 });957 it('should define the correct metadata (class).', () => {958 const metadataFunc = (controller: any) => metadata;959 @ApiDefineLink('link1', metadataFunc)960 class Controller {}961 deepStrictEqual(getMetadata('api:components:links', Controller), {962 link1: metadataFunc,963 });964 });965 it('should define the correct metadata (method).', () => {966 class Controller {967 @ApiDefineLink('link1', metadata)968 @ApiDefineLink('link2', metadata2)969 foo() { }970 }971 deepStrictEqual(getMetadata('api:components:links', Controller, 'foo'), {972 link1: metadata,973 link2: metadata2974 });975 });976});977describe('ApiDefineCallback', () => {978 const metadata: IApiCallback = {};979 const metadata2: IApiCallback = {};980 it('should define the correct metadata (class).', () => {981 @ApiDefineCallback('cb1', metadata)982 @ApiDefineCallback('cb2', metadata2)983 class Controller {}984 deepStrictEqual(getMetadata('api:components:callbacks', Controller), {985 cb1: metadata,986 cb2: metadata2987 });988 });989 it('should define the correct metadata (class & dynamic).', () => {990 const metadataFunc = (controller: any) => metadata;991 @ApiDefineCallback('cb1', metadataFunc)992 class Controller {}993 deepStrictEqual(getMetadata('api:components:callbacks', Controller), {994 cb1: metadataFunc,995 });996 });997 it('should define the correct metadata (method).', () => {998 class Controller {999 @ApiDefineCallback('cb1', metadata)1000 @ApiDefineCallback('cb2', metadata2)1001 foo() { }1002 }1003 deepStrictEqual(getMetadata('api:components:callbacks', Controller, 'foo'), {1004 cb1: metadata,1005 cb2: metadata21006 });1007 });...
atom-util.js
Source:atom-util.js
1var util = exports;2util.EscapedString = function(string) {3 this.string = string;4 this.toString = function() {5 return this.string;6 }7};8util.escape = function(value) {9 if (!value || value instanceof util.EscapedString) return value;10 return value.toString().replace("&", "&").replace("<", "<").replace('"', """);11};12util.getBody = function(object) {13 if (!object) return object;14 if (typeof object.getBody === "function")15 return object.getBody();16 if (object.getMetadata && object.getMetadata().getProfile) {17 var profile = object.getMetadata().getProfile();18 if (typeof profile.prototype.getBody === "function")19 return profile.prototype.getBody.apply(object);20 };21};22util.getLink = function(object) {23 var id = object.getId ? object.getId() : object.id;24 if (object.getMetadata && object.getMetadata().getProfile) {25 return util.escape("/" + object.getMetadata().getProfile().id + "/" + id);26 }27 return util.escape(id);28};29util.getTitle = function(object) {30 if (!object) return object;31 if (typeof object.getTitle === "function")32 return util.escape(object.getTitle());33 if (object.getMetadata && object.getMetadata().getProfile) {34 var profile = object.getMetadata().getProfile();35 if (typeof profile.prototype.getTitle === "function")36 return util.escape(profile.prototype.getTitle.apply(object));37 };38 return util.escape(object.id);39};40util.getUpdated = function(object) {41 if (typeof object.getUpdated === "function")42 return object.getUpdated();43 if (object.getMetadata && object.getMetadata()["last-modified"])44 return object.getMetadata()["last-modified"];45};46util.getRevision = function(object) {47 if (typeof object.getRevision === "function")48 return util.escape(object.getRevision());49 if (object.getMetadata && object.getMetadata()["etag"])50 return util.escape(object.getMetadata()["etag"]);51 //return "aa4asf45ewey";52};53util.getSummary = function(object) {54 if (!object) return object;55 if (typeof object.getSummary === "function")56 return util.escape(object.getSummary());57 if (object.getMetadata && object.getMetadata().getProfile) {58 var profile = object.getMetadata().getProfile();59 if (typeof profile.prototype.getSummary === "function")60 return util.escape(profile.prototype.getSummary.apply(object));61 };62 return util.escape("keys: " + Object.keys(object));63};64util.getContent = function(object) {65 if (!object) return object;66 if (typeof object.getContent === "function")67 return util.escape(object.getContent());68 if (object.getMetadata && object.getMetadata().getProfile) {69 var profile = object.getMetadata().getProfile();70 if (typeof profile.prototype.getContent === "function")71 return util.escape(profile.prototype.getContent.apply(object));72 };73 74 // fall back on default serialization75 var s = ' <dl class="properties">\n';76 for (var key in object) {77 if (typeof object[key] === "function") continue;78 if (typeof object[key] === "object") {79 if (object[key].$ref) {80 s += ' <dt>' + key + '</dt><dd><a href="' + object.id + "." + key + '">[link]</a>';81 if (key == "xml") s += ' <a target="_blank" href="' + object.id + '?http-x-edit">[edit]</a>';82 s += '</dd>';83 }84 else {85 s += ' <dt>' + key + '</dt><dd><a href="' + object.id + "." + key + '">' + object[key] + '</a></dd>';86 }87 }88 else {89 s += ' <dt>' + key + '</dt><dd>' + object[key] + '</dd>\n';90 }91 }92 s += ' </dl>\n';93 return s;...
Using AI Code Generation
1import { getMetaData } from 'storybook-root';2import { getMetaData } from 'storybook-root';3import { getMetaData } from 'storybook-root';4import { getMetaData } from 'storybook-root';5import { getMetaData } from 'storybook-root';6import { getMetaData } from 'storybook-root';7import { getMetaData } from 'storybook-root';8import { getMetaData } from 'storybook-root';9import { getMetaData } from 'storybook-root';10import { getMetaData } from 'storybook-root';11import { getMetaData } from 'storybook-root';12import { getMetaData } from 'storybook-root';13import { getMetaData } from 'storybook-root';
Using AI Code Generation
1var storybookRoot = require('storybook-root');2storybookRoot.getMetaData('test.js', function (err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var storybookRoot = require('storybook-root');10storybookRoot.getMetaData('test.js', function (err, data) {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var storybookRoot = require('storybook-root');18storybookRoot.getMetaData('test.js', function (err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var storybookRoot = require('storybook-root');26storybookRoot.getMetaData('test.js', function (err, data) {27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var storybookRoot = require('storybook-root');34storybookRoot.getMetaData('test.js', function (err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var storybookRoot = require('storybook-root');42storybookRoot.getMetaData('test.js', function (err, data) {43 if (err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49var storybookRoot = require('storybook-root');50storybookRoot.getMetaData('test.js', function (err, data) {51 if (err) {52 console.log(err);53 } else {54 console.log(data);55 }56});57var storybookRoot = require('storybook-root');58storybookRoot.getMetaData('test.js', function (err, data) {59 if (err) {60 console.log(err);61 } else {62 console.log(data);63 }64});65var storybookRoot = require('storybook-root');
Using AI Code Generation
1var storybook = require('storybook-root');2var story = storybook.getMetaData();3console.log(story);4{5 "dependencies": {6 }7}
Using AI Code Generation
1import { getMetaData } from 'storybook-root';2export { getMetaData } from './src/utils/getMetaData';3export const getMetaData = () => {4}5import { getMetaData } from 'storybook-root';6export { getMetaData } from './src/utils/getMetaData';7export const getMetaData = () => {8}9{10 "dependencies": {11 }12}
Using AI Code Generation
1import { getMetaData } from 'storybook-root';2const metaData = getMetaData();3import { getMetaData } from 'storybook-root';4const metaData = getMetaData();5import { getMetaData } from 'storybook-root';6const metaData = getMetaData();7import { getMetaData } from 'storybook-root';8const metaData = getMetaData();9import { getMetaData } from 'storybook-root';10const metaData = getMetaData();11import { getMetaData } from 'storybook-root';12const metaData = getMetaData();13import { getMetaData } from 'storybook-root';14const metaData = getMetaData();15import { getMetaData } from 'storybook-root';16const metaData = getMetaData();17import { getMetaData } from 'storybook-root';18const metaData = getMetaData();
Using AI Code Generation
1import { getMetaData } from 'storybook-root'2console.log(getMetaData())3export function getMetaData() {4 return {5 }6}7import { configure } from '@storybook/react'8import 'storybook-root'9function loadStories() {10}11configure(loadStories, module)12const path = require('path')13module.exports = (baseConfig, env, config) => {14 config.module.rules.push({15 include: path.resolve(__dirname, '../'),16 use: {17 options: {18 }19 }20 })21}
Using AI Code Generation
1import { getMetaData } from 'storybook-root';2const metaData = getMetaData('test.js');3import { getMetaData } from 'storybook-root';4const metaData = getMetaData('test.stories.js');5import { getMetaData } from 'storybook-root';6const metaData = getMetaData('test.stories.tsx');7import { getMetaData } from 'storybook-root';8const metaData = getMetaData('test.stories.mdx');9import { getMetaData } from 'storybook-root';10const metaData = getMetaData('test.stories.js');11import { getMetaData } from 'storybook-root';12const metaData = getMetaData('test.stories.tsx');13import { getMetaData } from 'storybook-root';14const metaData = getMetaData('test.stories.mdx');15import { getMetaData } from 'storybook-root';16const metaData = getMetaData('test.stories.js');
Using AI Code Generation
1var storybook = require('storybook-root');2storybook.getMetaData('test', 'test', function(data){3 console.log(data);4});5var storybook = require('storybook-root');6storybook.getMetaData('test', 'test', function(data){7 console.log(data);8});9var storybook = require('storybook-root');10storybook.getMetaData('test', 'test', function(data){11 console.log(data);12});13var storybook = require('storybook-root');14storybook.getMetaData('test', 'test', function(data){15 console.log(data);16});17var storybook = require('storybook-root');18storybook.getMetaData('test', 'test', function(data){19 console.log(data);20});21var storybook = require('storybook-root');22storybook.getMetaData('test', 'test', function(data){23 console.log(data);24});25var storybook = require('storybook-root');26storybook.getMetaData('test', 'test', function(data){27 console.log(data);28});29var storybook = require('storybook-root');30storybook.getMetaData('test', 'test', function(data){31 console.log(data);32});33var storybook = require('storybook-root');34storybook.getMetaData('test', 'test', function(data){35 console.log(data);36});37var storybook = require('storybook-root');38storybook.getMetaData('test', 'test', function(data){39 console.log(data);40});41var storybook = require('storybook-root');42storybook.getMetaData('test', 'test', function(data){43 console.log(data);44});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!