Skip to content

Commit

Permalink
update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Feb 14, 2024
1 parent a102a2f commit 50050ee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 379 deletions.
195 changes: 5 additions & 190 deletions tests/Generator/Client/resource/php_test/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,197 +15,12 @@

class Client extends ClientAbstract
{
/**
* Returns a collection
*
* @param int|null $startIndex
* @param int|null $count
* @param string|null $search
* @return TestResponse
* @throws ClientException
*/
public function getAll(?int $startIndex = null, ?int $count = null, ?string $search = null): TestResponse
public function product(): ProductTag
{
$url = $this->parser->url('/anything', [
]);

$options = [
'query' => $this->parser->query([
'startIndex' => $startIndex,
'count' => $count,
'search' => $search,
]),
];

try {
$response = $this->httpClient->request('GET', $url, $options);
$data = (string) $response->getBody();

return $this->parser->parse($data, TestResponse::class);
} catch (ClientException $e) {
throw $e;
} catch (BadResponseException $e) {
$data = (string) $e->getResponse()->getBody();

switch ($e->getResponse()->getStatusCode()) {
default:
throw new UnknownStatusCodeException('The server returned an unknown status code');
}
} catch (\Throwable $e) {
throw new ClientException('An unknown error occurred: ' . $e->getMessage());
}
}

/**
* Creates a new product
*
* @param TestRequest $payload
* @return TestResponse
* @throws ClientException
*/
public function create(TestRequest $payload): TestResponse
{
$url = $this->parser->url('/anything', [
]);

$options = [
'query' => $this->parser->query([
]),
'json' => $payload
];

try {
$response = $this->httpClient->request('POST', $url, $options);
$data = (string) $response->getBody();

return $this->parser->parse($data, TestResponse::class);
} catch (ClientException $e) {
throw $e;
} catch (BadResponseException $e) {
$data = (string) $e->getResponse()->getBody();

switch ($e->getResponse()->getStatusCode()) {
default:
throw new UnknownStatusCodeException('The server returned an unknown status code');
}
} catch (\Throwable $e) {
throw new ClientException('An unknown error occurred: ' . $e->getMessage());
}
}

/**
* Updates an existing product
*
* @param int $id
* @param TestRequest $payload
* @return TestResponse
* @throws ClientException
*/
public function update(int $id, TestRequest $payload): TestResponse
{
$url = $this->parser->url('/anything/:id', [
'id' => $id,
]);

$options = [
'query' => $this->parser->query([
]),
'json' => $payload
];

try {
$response = $this->httpClient->request('PUT', $url, $options);
$data = (string) $response->getBody();

return $this->parser->parse($data, TestResponse::class);
} catch (ClientException $e) {
throw $e;
} catch (BadResponseException $e) {
$data = (string) $e->getResponse()->getBody();

switch ($e->getResponse()->getStatusCode()) {
default:
throw new UnknownStatusCodeException('The server returned an unknown status code');
}
} catch (\Throwable $e) {
throw new ClientException('An unknown error occurred: ' . $e->getMessage());
}
}

/**
* Patches an existing product
*
* @param int $id
* @param TestRequest $payload
* @return TestResponse
* @throws ClientException
*/
public function patch(int $id, TestRequest $payload): TestResponse
{
$url = $this->parser->url('/anything/:id', [
'id' => $id,
]);

$options = [
'query' => $this->parser->query([
]),
'json' => $payload
];

try {
$response = $this->httpClient->request('PATCH', $url, $options);
$data = (string) $response->getBody();

return $this->parser->parse($data, TestResponse::class);
} catch (ClientException $e) {
throw $e;
} catch (BadResponseException $e) {
$data = (string) $e->getResponse()->getBody();

switch ($e->getResponse()->getStatusCode()) {
default:
throw new UnknownStatusCodeException('The server returned an unknown status code');
}
} catch (\Throwable $e) {
throw new ClientException('An unknown error occurred: ' . $e->getMessage());
}
}

/**
* Deletes an existing product
*
* @param int $id
* @return TestResponse
* @throws ClientException
*/
public function delete(int $id): TestResponse
{
$url = $this->parser->url('/anything/:id', [
'id' => $id,
]);

$options = [
'query' => $this->parser->query([
]),
];

try {
$response = $this->httpClient->request('DELETE', $url, $options);
$data = (string) $response->getBody();

return $this->parser->parse($data, TestResponse::class);
} catch (ClientException $e) {
throw $e;
} catch (BadResponseException $e) {
$data = (string) $e->getResponse()->getBody();

switch ($e->getResponse()->getStatusCode()) {
default:
throw new UnknownStatusCodeException('The server returned an unknown status code');
}
} catch (\Throwable $e) {
throw new ClientException('An unknown error occurred: ' . $e->getMessage());
}
return new ProductTag(
$this->httpClient,
$this->parser
);
}


Expand Down
186 changes: 7 additions & 179 deletions tests/Generator/Client/resource/typescript_test/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,187 +8,15 @@ import {ClientAbstract, CredentialsInterface, TokenStoreInterface} from "sdkgen-
import {HttpBearer} from "sdkgen-client"
import {ClientException, UnknownStatusCodeException} from "sdkgen-client";

import {TestRequest} from "./TestRequest";
import {TestResponse} from "./TestResponse";
import {ProductTag} from "./ProductTag";

export class Client extends ClientAbstract {
/**
* Returns a collection
*
* @returns {Promise<TestResponse>}
* @throws {ClientException}
*/
public async getAll(startIndex?: number, count?: number, search?: string): Promise<TestResponse> {
const url = this.parser.url('/anything', {
});

let params: AxiosRequestConfig = {
url: url,
method: 'GET',
params: this.parser.query({
'startIndex': startIndex,
'count': count,
'search': search,
}),
};

try {
const response = await this.httpClient.request<TestResponse>(params);
return response.data;
} catch (error) {
if (error instanceof ClientException) {
throw error;
} else if (axios.isAxiosError(error) && error.response) {
switch (error.response.status) {
default:
throw new UnknownStatusCodeException('The server returned an unknown status code');
}
} else {
throw new ClientException('An unknown error occurred: ' + String(error));
}
}
}

/**
* Creates a new product
*
* @returns {Promise<TestResponse>}
* @throws {ClientException}
*/
public async create(payload: TestRequest): Promise<TestResponse> {
const url = this.parser.url('/anything', {
});

let params: AxiosRequestConfig = {
url: url,
method: 'POST',
params: this.parser.query({
}),
data: payload
};

try {
const response = await this.httpClient.request<TestResponse>(params);
return response.data;
} catch (error) {
if (error instanceof ClientException) {
throw error;
} else if (axios.isAxiosError(error) && error.response) {
switch (error.response.status) {
default:
throw new UnknownStatusCodeException('The server returned an unknown status code');
}
} else {
throw new ClientException('An unknown error occurred: ' + String(error));
}
}
}

/**
* Updates an existing product
*
* @returns {Promise<TestResponse>}
* @throws {ClientException}
*/
public async update(id: number, payload: TestRequest): Promise<TestResponse> {
const url = this.parser.url('/anything/:id', {
'id': id,
});

let params: AxiosRequestConfig = {
url: url,
method: 'PUT',
params: this.parser.query({
}),
data: payload
};

try {
const response = await this.httpClient.request<TestResponse>(params);
return response.data;
} catch (error) {
if (error instanceof ClientException) {
throw error;
} else if (axios.isAxiosError(error) && error.response) {
switch (error.response.status) {
default:
throw new UnknownStatusCodeException('The server returned an unknown status code');
}
} else {
throw new ClientException('An unknown error occurred: ' + String(error));
}
}
}

/**
* Patches an existing product
*
* @returns {Promise<TestResponse>}
* @throws {ClientException}
*/
public async patch(id: number, payload: TestRequest): Promise<TestResponse> {
const url = this.parser.url('/anything/:id', {
'id': id,
});

let params: AxiosRequestConfig = {
url: url,
method: 'PATCH',
params: this.parser.query({
}),
data: payload
};

try {
const response = await this.httpClient.request<TestResponse>(params);
return response.data;
} catch (error) {
if (error instanceof ClientException) {
throw error;
} else if (axios.isAxiosError(error) && error.response) {
switch (error.response.status) {
default:
throw new UnknownStatusCodeException('The server returned an unknown status code');
}
} else {
throw new ClientException('An unknown error occurred: ' + String(error));
}
}
}

/**
* Deletes an existing product
*
* @returns {Promise<TestResponse>}
* @throws {ClientException}
*/
public async delete(id: number): Promise<TestResponse> {
const url = this.parser.url('/anything/:id', {
'id': id,
});

let params: AxiosRequestConfig = {
url: url,
method: 'DELETE',
params: this.parser.query({
}),
};

try {
const response = await this.httpClient.request<TestResponse>(params);
return response.data;
} catch (error) {
if (error instanceof ClientException) {
throw error;
} else if (axios.isAxiosError(error) && error.response) {
switch (error.response.status) {
default:
throw new UnknownStatusCodeException('The server returned an unknown status code');
}
} else {
throw new ClientException('An unknown error occurred: ' + String(error));
}
}
public product(): ProductTag
{
return new ProductTag(
this.httpClient,
this.parser
);
}


Expand Down
Loading

0 comments on commit 50050ee

Please sign in to comment.