Skip to content

Commit b94d232

Browse files
committed
feat(js): automation test 1
1 parent 4b8d926 commit b94d232

35 files changed

+1456
-14
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
node_modules
2+
.bash_profile
3+
.env
4+
dist
5+
yarn.lock
6+
7+
*/*/.openapi-generator
8+
*/*/.swagger-codegen
9+
*/*/node_modules
10+
*/*/dist
11+
*/*/yarn.lock
12+
*/*/.openapi-generator-ignore
13+
*/*/.swagger-codegen-ignore

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"trailingComma": "es5",
3+
"singleQuote": true,
4+
"printWidth": 100
5+
}

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# How to run
2+
3+
## Install and setup env
4+
5+
```bash
6+
yarn && export PACKAGE_VERSION='4.11.0' TS_POST_PROCESS_FILE='yarn prettier --write .'
7+
```
8+
9+
## Generate
10+
11+
```bash
12+
yarn generate
13+
```
14+
15+
## Install clients
16+
17+
```bash
18+
yarn install-clients
19+
```

app.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import {
2+
DefaultApi as DefaultOpenAPI,
3+
GetRecommendationsRequest,
4+
} from 'algoliasearch-client-javascript-openapi';
5+
import { DefaultApi as DefaultSwaggerAPI } from 'algoliasearch-client-javascript-swagger';
6+
// not exported by default?
7+
import { GetRecommendationsRequestModelEnum } from 'algoliasearch-client-javascript-swagger/dist/models';
8+
9+
const openApiClient = new DefaultOpenAPI();
10+
const swaggerClient = new DefaultSwaggerAPI();
11+
12+
async function testClients() {
13+
// test openapi gen
14+
try {
15+
const openApiResult = await openApiClient.getRecommendations(
16+
[
17+
{
18+
indexName: 'gstar_demo_test',
19+
model: GetRecommendationsRequest.ModelEnum['RelatedProducts'],
20+
objectID: 'abcd',
21+
},
22+
],
23+
'HYDY1KWTWB',
24+
'28cf6d38411215e2eef188e635216508'
25+
);
26+
27+
console.log('[1-RESPONSE]', openApiResult);
28+
} catch (e) {
29+
console.error('[1-ERROR]', e);
30+
}
31+
32+
// test swagger gen
33+
try {
34+
const swaggerResult = await swaggerClient.getRecommendations(
35+
[
36+
{
37+
indexName: 'gstar_demo_test',
38+
model: GetRecommendationsRequestModelEnum['RelatedProducts'],
39+
objectID: 'abcd',
40+
},
41+
],
42+
'HYDY1KWTWB',
43+
'28cf6d38411215e2eef188e635216508'
44+
);
45+
46+
console.log('[2-RESPONSE]', swaggerResult);
47+
} catch (e) {
48+
console.error('[2-ERROR]', e);
49+
}
50+
}
51+
52+
testClients();

openapitools.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
3+
"spaces": 2,
4+
"generator-cli": {
5+
"version": "5.2.1",
6+
"enablePostProcessFile": true,
7+
"generators": {
8+
"client": {
9+
"generatorName": "typescript-node",
10+
"output": "#{cwd}/output/client-openapi/",
11+
"glob": "spec.yml",
12+
"enablePostProcessFile": true,
13+
"gitHost": "algolia",
14+
"gitUserId": "algolia",
15+
"gitRepoId": "algoliasearch-client-javascript",
16+
"httpUserAgent": "Algolia for JavaScript (${PACKAGE_VERSION});",
17+
"additionalProperties": {
18+
"npmName": "algoliasearch-client-javascript-openapi",
19+
"supportsES6": "true",
20+
"npmVersion": "${PACKAGE_VERSION}"
21+
}
22+
}
23+
}
24+
}
25+
}

output/client-openapi/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
wwwroot/*.js
2+
node_modules
3+
typings
4+
dist

output/client-openapi/api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This is the entrypoint for the package
2+
export * from './api/apis';
3+
export * from './model/models';

output/client-openapi/api/apis.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export * from './defaultApi';
2+
import { DefaultApi } from './defaultApi';
3+
import * as http from 'http';
4+
5+
export class HttpError extends Error {
6+
constructor(public response: http.IncomingMessage, public body: any, public statusCode?: number) {
7+
super('HTTP request failed');
8+
this.name = 'HttpError';
9+
}
10+
}
11+
12+
export { RequestFile } from '../model/models';
13+
14+
export const APIS = [DefaultApi];
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/**
2+
* Recommend API
3+
* API powering the Recommend feature of Algolia.
4+
*
5+
* The version of the OpenAPI document: 0.1.0
6+
*
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
import localVarRequest from 'request';
14+
import http from 'http';
15+
16+
/* tslint:disable:no-unused-locals */
17+
import { GetRecommendationsRequest } from '../model/getRecommendationsRequest';
18+
import { GetRecommendationsResponse } from '../model/getRecommendationsResponse';
19+
20+
import { ObjectSerializer, Authentication, VoidAuth, Interceptor } from '../model/models';
21+
22+
import { HttpError, RequestFile } from './apis';
23+
24+
let defaultBasePath = 'https://test-1.algolianet.com';
25+
26+
// ===============================================
27+
// This file is autogenerated - Please do not edit
28+
// ===============================================
29+
30+
export enum DefaultApiApiKeys {}
31+
32+
export class DefaultApi {
33+
protected _basePath = defaultBasePath;
34+
protected _defaultHeaders: any = {};
35+
protected _useQuerystring: boolean = false;
36+
37+
protected authentications = {
38+
default: <Authentication>new VoidAuth(),
39+
};
40+
41+
protected interceptors: Interceptor[] = [];
42+
43+
constructor(basePath?: string);
44+
constructor(basePathOrUsername: string, password?: string, basePath?: string) {
45+
if (password) {
46+
if (basePath) {
47+
this.basePath = basePath;
48+
}
49+
} else {
50+
if (basePathOrUsername) {
51+
this.basePath = basePathOrUsername;
52+
}
53+
}
54+
}
55+
56+
set useQuerystring(value: boolean) {
57+
this._useQuerystring = value;
58+
}
59+
60+
set basePath(basePath: string) {
61+
this._basePath = basePath;
62+
}
63+
64+
set defaultHeaders(defaultHeaders: any) {
65+
this._defaultHeaders = defaultHeaders;
66+
}
67+
68+
get defaultHeaders() {
69+
return this._defaultHeaders;
70+
}
71+
72+
get basePath() {
73+
return this._basePath;
74+
}
75+
76+
public setDefaultAuthentication(auth: Authentication) {
77+
this.authentications.default = auth;
78+
}
79+
80+
public setApiKey(key: DefaultApiApiKeys, value: string) {
81+
(this.authentications as any)[DefaultApiApiKeys[key]].apiKey = value;
82+
}
83+
84+
public addInterceptor(interceptor: Interceptor) {
85+
this.interceptors.push(interceptor);
86+
}
87+
88+
/**
89+
*
90+
* @summary Get recommendations for the given requests.
91+
* @param getRecommendationsRequest
92+
* @param xAlgoliaApplicationId Algolia appID
93+
* @param xAlgoliaAPIKey Algolia API key
94+
*/
95+
public async getRecommendations(
96+
getRecommendationsRequest: Array<GetRecommendationsRequest>,
97+
xAlgoliaApplicationId?: string,
98+
xAlgoliaAPIKey?: string,
99+
options: { headers: { [name: string]: string } } = { headers: {} }
100+
): Promise<{ response: http.IncomingMessage; body: GetRecommendationsResponse }> {
101+
const localVarPath = this.basePath + '/1/indexes/*/recommendations';
102+
let localVarQueryParameters: any = {};
103+
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
104+
const produces = ['application/json'];
105+
// give precedence to 'application/json'
106+
if (produces.indexOf('application/json') >= 0) {
107+
localVarHeaderParams.Accept = 'application/json';
108+
} else {
109+
localVarHeaderParams.Accept = produces.join(',');
110+
}
111+
let localVarFormParams: any = {};
112+
113+
// verify required parameter 'getRecommendationsRequest' is not null or undefined
114+
if (getRecommendationsRequest === null || getRecommendationsRequest === undefined) {
115+
throw new Error(
116+
'Required parameter getRecommendationsRequest was null or undefined when calling getRecommendations.'
117+
);
118+
}
119+
120+
localVarHeaderParams['X-Algolia-Application-Id'] = ObjectSerializer.serialize(
121+
xAlgoliaApplicationId,
122+
'string'
123+
);
124+
localVarHeaderParams['X-Algolia-API-Key'] = ObjectSerializer.serialize(
125+
xAlgoliaAPIKey,
126+
'string'
127+
);
128+
(<any>Object).assign(localVarHeaderParams, options.headers);
129+
130+
let localVarUseFormData = false;
131+
132+
let localVarRequestOptions: localVarRequest.Options = {
133+
method: 'POST',
134+
qs: localVarQueryParameters,
135+
headers: localVarHeaderParams,
136+
uri: localVarPath,
137+
useQuerystring: this._useQuerystring,
138+
json: true,
139+
body: ObjectSerializer.serialize(
140+
getRecommendationsRequest,
141+
'Array<GetRecommendationsRequest>'
142+
),
143+
};
144+
145+
let authenticationPromise = Promise.resolve();
146+
authenticationPromise = authenticationPromise.then(() =>
147+
this.authentications.default.applyToRequest(localVarRequestOptions)
148+
);
149+
150+
let interceptorPromise = authenticationPromise;
151+
for (const interceptor of this.interceptors) {
152+
interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions));
153+
}
154+
155+
return interceptorPromise.then(() => {
156+
if (Object.keys(localVarFormParams).length) {
157+
if (localVarUseFormData) {
158+
(<any>localVarRequestOptions).formData = localVarFormParams;
159+
} else {
160+
localVarRequestOptions.form = localVarFormParams;
161+
}
162+
}
163+
return new Promise<{ response: http.IncomingMessage; body: GetRecommendationsResponse }>(
164+
(resolve, reject) => {
165+
localVarRequest(localVarRequestOptions, (error, response, body) => {
166+
if (error) {
167+
reject(error);
168+
} else {
169+
body = ObjectSerializer.deserialize(body, 'GetRecommendationsResponse');
170+
if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) {
171+
resolve({ response: response, body: body });
172+
} else {
173+
reject(new HttpError(response, body, response.statusCode));
174+
}
175+
}
176+
});
177+
}
178+
);
179+
});
180+
}
181+
}

output/client-openapi/git_push.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/sh
2+
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3+
#
4+
# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com"
5+
6+
git_user_id=$1
7+
git_repo_id=$2
8+
release_note=$3
9+
git_host=$4
10+
11+
if [ "$git_host" = "" ]; then
12+
git_host="algolia"
13+
echo "[INFO] No command line input provided. Set \$git_host to $git_host"
14+
fi
15+
16+
if [ "$git_user_id" = "" ]; then
17+
git_user_id="algolia"
18+
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
19+
fi
20+
21+
if [ "$git_repo_id" = "" ]; then
22+
git_repo_id="algoliasearch-client-javascript"
23+
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
24+
fi
25+
26+
if [ "$release_note" = "" ]; then
27+
release_note="Minor update"
28+
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
29+
fi
30+
31+
# Initialize the local directory as a Git repository
32+
git init
33+
34+
# Adds the files in the local repository and stages them for commit.
35+
git add .
36+
37+
# Commits the tracked changes and prepares them to be pushed to a remote repository.
38+
git commit -m "$release_note"
39+
40+
# Sets the new remote
41+
git_remote=`git remote`
42+
if [ "$git_remote" = "" ]; then # git remote not defined
43+
44+
if [ "$GIT_TOKEN" = "" ]; then
45+
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
46+
git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
47+
else
48+
git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git
49+
fi
50+
51+
fi
52+
53+
git pull origin master
54+
55+
# Pushes (Forces) the changes in the local repository up to the remote repository
56+
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
57+
git push origin master 2>&1 | grep -v 'To https'
58+

0 commit comments

Comments
 (0)