qa 0.0.14 → 0.0.16
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/commands/init.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { intro, outro, spinner } from '@clack/prompts';
|
|
2
2
|
import { getAccessToken } from '../auth.js';
|
|
3
|
-
import {
|
|
3
|
+
import { fetchProjectNames, generateTests, validateAuthToken, createSpecification } from './utils/index.js';
|
|
4
4
|
import { askTestingType, askSpecLocation, askProjectDetails, askSecurityParams, askServerParams, askForUserAuth } from './utils/prompts.js';
|
|
5
5
|
import { CLI_EPILOGUE } from '../constants.js';
|
|
6
6
|
export const command = 'init [option]';
|
|
@@ -24,7 +24,7 @@ export const handler = async (argv) => {
|
|
|
24
24
|
const s = spinner();
|
|
25
25
|
intro('Start new CodelessQA project');
|
|
26
26
|
await askTestingType();
|
|
27
|
-
const { specPath,
|
|
27
|
+
const { specPath, spec } = await askSpecLocation();
|
|
28
28
|
s.start('Looking up user account...');
|
|
29
29
|
let userAuth = await validateAuthToken(token);
|
|
30
30
|
if (!userAuth.valid) {
|
|
@@ -33,29 +33,13 @@ export const handler = async (argv) => {
|
|
|
33
33
|
token = await askForUserAuth();
|
|
34
34
|
userAuth = await validateAuthToken(token);
|
|
35
35
|
}
|
|
36
|
-
/**
|
|
37
|
-
* start uploading the specification while continue to have the user answer questions
|
|
38
|
-
*/
|
|
39
|
-
const uploadProcess = (async () => {
|
|
40
|
-
const presignedUrl = await getPresignUrl(token, specPath);
|
|
41
|
-
await uploadSpecification(presignedUrl, specString);
|
|
42
|
-
return waitForUploadFinishes(presignedUrl);
|
|
43
|
-
})();
|
|
44
36
|
const projectNames = await fetchProjectNames(token);
|
|
45
37
|
s.stop(`User ${userAuth.email} authenticated!`);
|
|
46
38
|
const projectProps = await askProjectDetails(projectNames, spec);
|
|
47
39
|
const securityParams = await askSecurityParams(spec);
|
|
48
40
|
const serverParam = await askServerParams(spec);
|
|
49
41
|
s.start('Uploading specification...');
|
|
50
|
-
const
|
|
51
|
-
if (fileOrError instanceof Error) {
|
|
52
|
-
s.stop();
|
|
53
|
-
outro(fileOrError.message);
|
|
54
|
-
process.exit(0);
|
|
55
|
-
}
|
|
56
|
-
s.stop(`Specification ${spec.info.title} (${spec.info.version}) uploaded!`);
|
|
57
|
-
s.start('Creating project...');
|
|
58
|
-
const id = await createSpecification(token, projectProps, fileOrError, s);
|
|
42
|
+
const id = await createSpecification(token, projectProps, specPath, s);
|
|
59
43
|
s.stop(`Project "${projectProps.name}" created!`);
|
|
60
44
|
s.start('Creating API tests...');
|
|
61
45
|
await generateTests(token, id, s, { securityParams, serverParam });
|
|
@@ -3,37 +3,6 @@ import type { ProjectProps } from './prompts.js';
|
|
|
3
3
|
type Spinner = {
|
|
4
4
|
stop: () => void;
|
|
5
5
|
};
|
|
6
|
-
export declare function getPresignUrl(token: string, specPath: string): Promise<{
|
|
7
|
-
url: string;
|
|
8
|
-
key: string;
|
|
9
|
-
fileName: string;
|
|
10
|
-
fileType: string;
|
|
11
|
-
fileUrl: string;
|
|
12
|
-
pollingJwt: string;
|
|
13
|
-
pollingUrl: string;
|
|
14
|
-
contentDisposition: string;
|
|
15
|
-
fields: {
|
|
16
|
-
key: string;
|
|
17
|
-
acl: string;
|
|
18
|
-
"Content-Type": string;
|
|
19
|
-
"Content-Disposition": string;
|
|
20
|
-
bucket: string;
|
|
21
|
-
"X-Amz-Algorithm": string;
|
|
22
|
-
"X-Amz-Credential": string;
|
|
23
|
-
"X-Amz-Date": string;
|
|
24
|
-
Policy: string;
|
|
25
|
-
"X-Amz-Signature": string;
|
|
26
|
-
};
|
|
27
|
-
customId?: any;
|
|
28
|
-
}>;
|
|
29
|
-
export declare function uploadSpecification(presignedUrl: {
|
|
30
|
-
url: string;
|
|
31
|
-
fields: Record<string, string>;
|
|
32
|
-
}, specString: string): Promise<void>;
|
|
33
|
-
export declare function waitForUploadFinishes(presignedUrl: {
|
|
34
|
-
pollingUrl: string;
|
|
35
|
-
pollingJwt: string;
|
|
36
|
-
}): Promise<string>;
|
|
37
6
|
export declare function createSpecification(token: string, projectProps: ProjectProps, file: string, spinner: Spinner): Promise<string>;
|
|
38
7
|
export declare function generateTests(token: string, id: string, spinner: Spinner, body: {
|
|
39
8
|
securityParams: SecurityObject[];
|
|
@@ -1,80 +1,8 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fs from 'node:fs/promises';
|
|
3
1
|
import { outro } from '@clack/prompts';
|
|
4
2
|
import { getAuthenticatedClient } from '@codeless.qa/contracts/client';
|
|
5
|
-
export async function getPresignUrl(token, specPath) {
|
|
6
|
-
const client = getAuthenticatedClient(token);
|
|
7
|
-
const stat = await fs.stat(specPath);
|
|
8
|
-
const presigned = await client.specification.upload({
|
|
9
|
-
query: { actionType: 'upload', slug: 'openAPISpecUploader' },
|
|
10
|
-
body: {
|
|
11
|
-
files: [{
|
|
12
|
-
name: path.basename(specPath),
|
|
13
|
-
size: stat.size,
|
|
14
|
-
type: 'application/json'
|
|
15
|
-
}]
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
if (presigned.status !== 200) {
|
|
19
|
-
const error = typeof presigned.body === 'object' && presigned.body && 'error' in presigned.body && presigned.body.error instanceof Error
|
|
20
|
-
? presigned.body.error
|
|
21
|
-
: new Error('Unknown error');
|
|
22
|
-
throw error;
|
|
23
|
-
}
|
|
24
|
-
return presigned.body[0];
|
|
25
|
-
}
|
|
26
|
-
export async function uploadSpecification(presignedUrl, specString) {
|
|
27
|
-
const formData = new FormData();
|
|
28
|
-
for (const [key, value] of Object.entries(presignedUrl.fields)) {
|
|
29
|
-
formData.append(key, value);
|
|
30
|
-
}
|
|
31
|
-
formData.append('file', Buffer.from(specString));
|
|
32
|
-
const res = await fetch(presignedUrl.url, {
|
|
33
|
-
method: 'POST',
|
|
34
|
-
body: formData,
|
|
35
|
-
});
|
|
36
|
-
if (res.status !== 204) {
|
|
37
|
-
const error = typeof res.body === 'object' && res.body && 'error' in res.body && res.body.error instanceof Error
|
|
38
|
-
? res.body.error
|
|
39
|
-
: new Error('Unknown error');
|
|
40
|
-
throw error;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
const UPLOAD_TIMEOUT = 1000 * 60;
|
|
44
|
-
export async function waitForUploadFinishes(presignedUrl) {
|
|
45
|
-
const start = Date.now();
|
|
46
|
-
let finalKey;
|
|
47
|
-
while (true) {
|
|
48
|
-
const waitRes = await fetch(presignedUrl.pollingUrl, {
|
|
49
|
-
headers: {
|
|
50
|
-
authorization: presignedUrl.pollingJwt
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
if (waitRes.status !== 200) {
|
|
54
|
-
const error = typeof waitRes.body === 'object' && waitRes.body && 'error' in waitRes.body && waitRes.body.error instanceof Error
|
|
55
|
-
? waitRes.body.error
|
|
56
|
-
: new Error('Unknown error');
|
|
57
|
-
throw error;
|
|
58
|
-
}
|
|
59
|
-
const body = await waitRes.json();
|
|
60
|
-
if (body.status === 'done') {
|
|
61
|
-
finalKey = body.callbackData.key;
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
if (Date.now() - start > UPLOAD_TIMEOUT) {
|
|
65
|
-
outro(`Timeout after ${UPLOAD_TIMEOUT / 1000} seconds!`);
|
|
66
|
-
process.exit(0);
|
|
67
|
-
}
|
|
68
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
69
|
-
}
|
|
70
|
-
if (!finalKey) {
|
|
71
|
-
throw new Error('Upload failed!');
|
|
72
|
-
}
|
|
73
|
-
return finalKey;
|
|
74
|
-
}
|
|
75
3
|
export async function createSpecification(token, projectProps, file, spinner) {
|
|
76
4
|
const client = getAuthenticatedClient(token);
|
|
77
|
-
const resSpecCreation = await client.
|
|
5
|
+
const resSpecCreation = await client.specification.create({
|
|
78
6
|
body: {
|
|
79
7
|
...projectProps,
|
|
80
8
|
file
|
|
@@ -66,7 +66,7 @@ export async function askSpecLocation() {
|
|
|
66
66
|
}
|
|
67
67
|
const specString = JSON.stringify(spec);
|
|
68
68
|
await fsp.writeFile(filePath, specString, 'utf8');
|
|
69
|
-
return { spec, specPath: filePath
|
|
69
|
+
return { spec, specPath: filePath };
|
|
70
70
|
}
|
|
71
71
|
catch (err) {
|
|
72
72
|
const error = err instanceof Error ? err : new Error('Unknown error');
|
|
@@ -77,7 +77,7 @@ export async function askSpecLocation() {
|
|
|
77
77
|
try {
|
|
78
78
|
const specString = fs.readFileSync(specPath, 'utf8');
|
|
79
79
|
const spec = JSON.parse(specString);
|
|
80
|
-
return { spec, specPath
|
|
80
|
+
return { spec, specPath };
|
|
81
81
|
}
|
|
82
82
|
catch (err) {
|
|
83
83
|
const error = err instanceof Error ? err : new Error('Unknown error');
|
|
@@ -100,7 +100,7 @@ export async function askProjectDetails(existingProjectNames, spec) {
|
|
|
100
100
|
};
|
|
101
101
|
if (key === 'name') {
|
|
102
102
|
opts.validate = (value) => existingProjectNames.includes(value)
|
|
103
|
-
? `Project
|
|
103
|
+
? `Project name "${value}" already exists`
|
|
104
104
|
: undefined;
|
|
105
105
|
}
|
|
106
106
|
const value = await text(opts);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qa",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"author": "Christian Bromann <christian@codeless.qa>",
|
|
5
5
|
"description": "Codeless QA CLI",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"uuid": "^9.0.1",
|
|
20
20
|
"ws": "^8.17.0",
|
|
21
21
|
"yargs": "^17.7.2",
|
|
22
|
-
"@codeless.qa/contracts": "0.0.
|
|
22
|
+
"@codeless.qa/contracts": "0.0.6"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"replace-in-files-cli": "^3.0.0",
|