Skip to content

Commit

Permalink
remove api version control
Browse files Browse the repository at this point in the history
  • Loading branch information
regevbr committed Jun 2, 2019
1 parent 79f786c commit 7ad26b7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 230 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## Development
- nothing yet

## v1.0.0

[diff](https://github.com/PruvoNet/cronicle-client/compare/v0.2.0...v1.0.0)

### Removed

- removed option to set api version as new version will require a new class with different types anyways...

## v0.2.0

[diff](https://github.com/PruvoNet/cronicle-client/compare/v0.1.0...v0.2.0)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cronicle-client",
"version": "0.2.0",
"version": "1.0.0",
"description": "Light Cronicle node client with full TypeScript support",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 1 addition & 5 deletions src/CronicleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import {
} from './requestResponseTypes';
import {IBasePlugins} from './plugins';

const DEFAULT_API_VERSION = 'v1';

const enum HttpMethods {
POST = 'POST',
GET = 'GET',
Expand Down Expand Up @@ -51,7 +49,6 @@ export class CronicleClient<Categories extends string = BaseCategories,

private readonly _headers: any;
private readonly _baseUrl: string;
private readonly _apiVersion: string;

constructor(opts: ICronicleClientOptions) {
if (!opts.masterUrl) {
Expand All @@ -61,7 +58,6 @@ export class CronicleClient<Categories extends string = BaseCategories,
throw new Error('cronicle api key is required');
}
this._baseUrl = `${opts.masterUrl.replace(/\/$/, '')}/api/app`;
this._apiVersion = opts.apiVersion || DEFAULT_API_VERSION;
this._headers = {
'X-API-Key': opts.apiKey,
};
Expand Down Expand Up @@ -153,6 +149,6 @@ export class CronicleClient<Categories extends string = BaseCategories,

private _getMethodUrl(operation: string, query?: IBodyOrQuery) {
const queryString = `${query ? '?' : ''}${query ? qs.stringify(query) : ''}`;
return `${this._baseUrl}/${operation}/${this._apiVersion}${queryString}`;
return `${this._baseUrl}/${operation}/v1${queryString}`;
}
}
224 changes: 0 additions & 224 deletions test/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,29 +334,6 @@ describe('cronicle client', () => {
});
});

it('should get event with custom api version', () => {
const apiVersion = 'v2';
const client = new cronicleClientStubbed({masterUrl, apiKey, apiVersion});
const response = {code: 0};
requestStub.resolves(response);
const id = 'myId';
return client.getEvent({id})
.then((resp) => {
expect(requestStub.firstCall.args[0]).to.eql({
body: {
id,
},
headers: {
'X-API-Key': apiKey,
},
json: true,
method: 'POST',
url: `${masterUrl}/api/app/get_event/${apiVersion}`,
});
expect(resp).to.eq(response);
});
});

});

describe('get schedule', () => {
Expand Down Expand Up @@ -456,26 +433,6 @@ limit=${limit}&offset=${offset}`,
});
});

it('should get schedule with custom api version', () => {
const apiVersion = 'v2';
const client = new cronicleClientStubbed({masterUrl, apiKey, apiVersion});
const response = {code: 0};
requestStub.resolves(response);
return client.getSchedule()
.then((resp) => {
expect(requestStub.firstCall.args[0]).to.eql({
body: undefined,
headers: {
'X-API-Key': apiKey,
},
json: true,
method: 'GET',
url: `${masterUrl}/api/app/get_schedule/${apiVersion}`,
});
expect(resp).to.eq(response);
});
});

});

describe('run event', () => {
Expand Down Expand Up @@ -543,31 +500,6 @@ limit=${limit}&offset=${offset}`,
});
});

it('should run event with custom api version', () => {
const apiVersion = 'v2';
const client = new cronicleClientStubbed({masterUrl, apiKey, apiVersion});
const response = {code: 0};
requestStub.resolves(response);
const id = 'myId';
const request = {
id,
log_max_size: 30,
};
return client.runEvent(request)
.then((resp) => {
expect(requestStub.firstCall.args[0]).to.eql({
body: request,
headers: {
'X-API-Key': apiKey,
},
json: true,
method: 'POST',
url: `${masterUrl}/api/app/run_event/${apiVersion}`,
});
expect(resp).to.eq(response);
});
});

});

describe('create event', () => {
Expand Down Expand Up @@ -799,39 +731,6 @@ limit=${limit}&offset=${offset}`,
});
});

it('should create event with custom api version', () => {
const apiVersion = 'v2';
const client = new cronicleClientStubbed({masterUrl, apiKey, apiVersion});
const response = {code: 0};
requestStub.resolves(response);
const request = {
title: 'myTitle',
enabled: NumberedBoolean.TRUE,
category: BaseCategories.GENERAL,
target: BaseTargets.MAIN,
plugin: basePlugins.shellplug,
params: {
script: 'myScript',
annotate: NumberedBoolean.FALSE,
json: NumberedBoolean.TRUE,
},
log_max_size: 30,
};
return client.createEvent(request)
.then((resp) => {
expect(requestStub.firstCall.args[0]).to.eql({
body: request,
headers: {
'X-API-Key': apiKey,
},
json: true,
method: 'POST',
url: `${masterUrl}/api/app/create_event/${apiVersion}`,
});
expect(resp).to.eq(response);
});
});

});

describe('update event', () => {
Expand Down Expand Up @@ -876,32 +775,6 @@ limit=${limit}&offset=${offset}`,
});
});

it('should update event with custom api version', () => {
const apiVersion = 'v2';
const client = new cronicleClientStubbed({masterUrl, apiKey, apiVersion});
const response = {code: 0};
requestStub.resolves(response);
const id = 'myId';
const request = {
id,
timeout: 30,
reset_cursor: NumberedBoolean.TRUE,
};
return client.updateEvent(request)
.then((resp) => {
expect(requestStub.firstCall.args[0]).to.eql({
body: request,
headers: {
'X-API-Key': apiKey,
},
json: true,
method: 'POST',
url: `${masterUrl}/api/app/update_event/${apiVersion}`,
});
expect(resp).to.eq(response);
});
});

});

describe('update job', () => {
Expand Down Expand Up @@ -946,32 +819,6 @@ limit=${limit}&offset=${offset}`,
});
});

it('should update job with custom api version', () => {
const apiVersion = 'v2';
const client = new cronicleClientStubbed({masterUrl, apiKey, apiVersion});
const response = {code: 0};
requestStub.resolves(response);
const id = 'myId';
const request = {
id,
timeout: 30,
reset_cursor: NumberedBoolean.TRUE,
};
return client.updateJob(request)
.then((resp) => {
expect(requestStub.firstCall.args[0]).to.eql({
body: request,
headers: {
'X-API-Key': apiKey,
},
json: true,
method: 'POST',
url: `${masterUrl}/api/app/update_job/${apiVersion}`,
});
expect(resp).to.eq(response);
});
});

});

describe('delete event', () => {
Expand Down Expand Up @@ -1015,31 +862,6 @@ limit=${limit}&offset=${offset}`,
});
});

it('should delete event with custom api version', () => {
const apiVersion = 'v2';
const client = new cronicleClientStubbed({masterUrl, apiKey, apiVersion});
const response = {code: 0};
requestStub.resolves(response);
const id = 'myId';
const request = {
id,
log_max_size: 30,
};
return client.deleteEvent(request)
.then((resp) => {
expect(requestStub.firstCall.args[0]).to.eql({
body: request,
headers: {
'X-API-Key': apiKey,
},
json: true,
method: 'POST',
url: `${masterUrl}/api/app/delete_event/${apiVersion}`,
});
expect(resp).to.eq(response);
});
});

});

describe('abort job', () => {
Expand Down Expand Up @@ -1082,31 +904,6 @@ limit=${limit}&offset=${offset}`,
});
});

it('should abort job with custom api version', () => {
const apiVersion = 'v2';
const client = new cronicleClientStubbed({masterUrl, apiKey, apiVersion});
const response = {code: 0};
requestStub.resolves(response);
const id = 'myId';
const request = {
id,
log_max_size: 30,
};
return client.abortJob(request)
.then((resp) => {
expect(requestStub.firstCall.args[0]).to.eql({
body: request,
headers: {
'X-API-Key': apiKey,
},
json: true,
method: 'POST',
url: `${masterUrl}/api/app/abort_job/${apiVersion}`,
});
expect(resp).to.eq(response);
});
});

});

describe('get job status', () => {
Expand Down Expand Up @@ -1146,27 +943,6 @@ limit=${limit}&offset=${offset}`,
});
});

it('should get job status with custom api version', () => {
const apiVersion = 'v2';
const client = new cronicleClientStubbed({masterUrl, apiKey, apiVersion});
const response = {code: 0};
requestStub.resolves(response);
const id = 'myId';
return client.getJobStatus({id})
.then((resp) => {
expect(requestStub.firstCall.args[0]).to.eql({
body: undefined,
headers: {
'X-API-Key': apiKey,
},
json: true,
method: 'GET',
url: `${masterUrl}/api/app/get_job_status/${apiVersion}?id=${id}`,
});
expect(resp).to.eq(response);
});
});

});

});
Expand Down

0 comments on commit 7ad26b7

Please sign in to comment.