qa 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export async function pullTestSuite(client, project) {
2
- const apis = await client.specifications.get();
2
+ const apis = await client.specifications.get().catch((error) => {
3
+ throw new Error(`Failed to fetch APIs: ${error} (${error.cause.code})`);
4
+ });
3
5
  if (apis.status !== 200) {
4
6
  const error = apis.status === 401 ? apis.body.error : 'unknown';
5
7
  throw new Error(`Failed to fetch APIs: ${error}`);
@@ -36,13 +36,13 @@ export const handler = async (argv) => {
36
36
  const projectNames = await fetchProjectNames(token);
37
37
  s.stop(`User ${userAuth.email} authenticated!`);
38
38
  const projectProps = await askProjectDetails(projectNames, spec);
39
- const securityParams = await askSecurityParams(spec);
40
- const serverParam = await askServerParams(spec);
39
+ const securityPayloads = await askSecurityParams(spec);
40
+ const serverObject = await askServerParams(spec);
41
41
  s.start('Uploading specification...');
42
42
  const id = await createSpecification(token, projectProps, specPath, s);
43
43
  s.stop(`Project "${projectProps.name}" created!`);
44
44
  s.start('Creating API tests...');
45
- await generateTests(token, id, s, { securityParams, serverParam });
45
+ await generateTests(token, id, s, { securityPayloads, serverObject });
46
46
  s.stop('API tests created!');
47
47
  outro(`You're all set!\n\nNow run your first test with:\n> qa test "${projectProps.name}"`);
48
48
  };
@@ -1,13 +1,10 @@
1
- import type { SecurityObject, ServerObject } from '@codeless.qa/contracts';
1
+ import type { SpecificationRequest } from '@codeless.qa/contracts';
2
2
  import type { ProjectProps } from './prompts.js';
3
3
  type Spinner = {
4
4
  stop: () => void;
5
5
  };
6
6
  export declare function createSpecification(token: string, projectProps: ProjectProps, file: string, spinner: Spinner): Promise<string>;
7
- export declare function generateTests(token: string, id: string, spinner: Spinner, body: {
8
- securityParams: SecurityObject[];
9
- serverParam: ServerObject;
10
- }): Promise<void>;
7
+ export declare function generateTests(token: string, id: string, spinner: Spinner, body: SpecificationRequest['generate']['body']): Promise<void>;
11
8
  export declare function fetchProjectNames(token: string): Promise<string[]>;
12
9
  export declare function validateAuthToken(token: string): Promise<{
13
10
  valid: false;
@@ -22,10 +22,7 @@ export async function generateTests(token, id, spinner, body) {
22
22
  const client = getAuthenticatedClient(token);
23
23
  const resTests = await client.specification.generate({
24
24
  params: { id },
25
- body: {
26
- securityObjects: body.securityParams,
27
- server: body.serverParam
28
- }
25
+ body
29
26
  });
30
27
  if (resTests.status !== 200 || 'error' in resTests.body) {
31
28
  spinner.stop();
@@ -1,4 +1,4 @@
1
- import { type SecurityObject, ServerObject } from '@codeless.qa/contracts';
1
+ import { type ServerObject, type SpecificationRequest } from '@codeless.qa/contracts';
2
2
  import { type OpenAPIV3 } from 'openapi-types';
3
3
  export declare function askTestingType(): Promise<string>;
4
4
  export declare function askSpecLocation(): Promise<{
@@ -11,7 +11,9 @@ export interface ProjectProps {
11
11
  version: string;
12
12
  }
13
13
  export declare function askProjectDetails(existingProjectNames: string[], spec: OpenAPIV3.Document): Promise<ProjectProps>;
14
- export declare function askSecurityParams(spec: OpenAPIV3.Document): Promise<SecurityObject[]>;
14
+ type SecurityPayloads = SpecificationRequest['generate']['body']['securityPayloads'];
15
+ export declare function askSecurityParams(spec: OpenAPIV3.Document): Promise<SecurityPayloads>;
15
16
  export declare function askServerParams(spec: OpenAPIV3.Document): Promise<ServerObject>;
16
17
  export declare function askForUserAuth(): Promise<string>;
18
+ export {};
17
19
  //# sourceMappingURL=prompts.d.ts.map
@@ -2,7 +2,6 @@ import os from 'node:os';
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import fsp from 'node:fs/promises';
5
- import { TestParameterType } from '@codeless.qa/contracts';
6
5
  import { select, text, confirm, outro, isCancel } from '@clack/prompts';
7
6
  import { handler as loginFlow } from '../login.js';
8
7
  export async function askTestingType() {
@@ -117,11 +116,11 @@ export async function askSecurityParams(spec) {
117
116
  !spec.components.securitySchemes ||
118
117
  (Array.isArray(spec.components.securitySchemes) &&
119
118
  spec.components.securitySchemes.length === 0)) {
120
- return [];
119
+ return {};
121
120
  }
122
- const securitySchemes = new Set(Object.values(spec.components.securitySchemes).filter((schema) => 'type' in schema));
123
- const securityObjects = [];
124
- for (const secScheme of securitySchemes) {
121
+ const securitySchemes = new Set(Object.entries(spec.components.securitySchemes).filter(([, schema]) => 'type' in schema));
122
+ const securityObjects = {};
123
+ for (const [name, secScheme] of securitySchemes) {
125
124
  const isBasicAuth = secScheme.type === 'http' && secScheme.scheme === 'basic';
126
125
  const isJWTAuth = secScheme.type === 'http' && secScheme.scheme === 'bearer' && secScheme.bearerFormat === 'JWT';
127
126
  const message = isBasicAuth
@@ -150,17 +149,13 @@ export async function askSecurityParams(spec) {
150
149
  }
151
150
  const scope = secScheme.in.slice(0, 1).toUpperCase() +
152
151
  secScheme.in.slice(1);
153
- securityObjects.push({
154
- id: Math.random().toString(36).slice(2).toLowerCase(),
155
- type: TestParameterType.Security,
156
- payload: {
157
- name: isBasicAuth || isJWTAuth
158
- ? 'Authorization'
159
- : secScheme.name,
160
- value,
161
- scope
162
- }
163
- });
152
+ securityObjects[name] = {
153
+ name: isBasicAuth || isJWTAuth
154
+ ? 'Authorization'
155
+ : secScheme.name,
156
+ value,
157
+ scope
158
+ };
164
159
  }
165
160
  return securityObjects;
166
161
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qa",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "author": "Christian Bromann <christian@codeless.qa>",
5
5
  "description": "Codeless QA CLI",
6
6
  "license": "Apache-2.0",
@@ -16,14 +16,14 @@
16
16
  "@types/yargs": "^17.0.32",
17
17
  "openapi-types": "^12.1.3",
18
18
  "tap-mocha-reporter": "^5.0.4",
19
- "uuid": "^9.0.1",
19
+ "uuid": "^11.0.3",
20
20
  "ws": "^8.17.0",
21
21
  "yargs": "^17.7.2",
22
- "@codeless.qa/contracts": "0.0.6"
22
+ "@codeless.qa/contracts": "0.0.8"
23
23
  },
24
24
  "devDependencies": {
25
25
  "replace-in-files-cli": "^3.0.0",
26
- "typescript": "5.6.2"
26
+ "typescript": "^5.6.3"
27
27
  },
28
28
  "scripts": {
29
29
  "build": "run-s build:*",