Skip to content

Commit

Permalink
Sanketika-obsrv/issue-tracker#273 feat: updated testcases for latest …
Browse files Browse the repository at this point in the history
…changes
  • Loading branch information
GayathriSrividya committed May 16, 2024
1 parent 5e85253 commit 6c15005
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 2 deletions.
81 changes: 79 additions & 2 deletions api-service/src/test/DatasourceTestService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,26 @@ describe('Datasource APIS', () => {
done();
});
})
it("should create datalake datasource", (done)=>{
chai.spy.on(dbConnector, "execute", () => {
return Promise.resolve([])
})
chai
.request(app)
.post(config.apiDatasourceSaveEndPoint)
.send(TestDataSource.VALID_DATALAKE_SCHEMA)
.end((err, res) => {
res.should.have.status(httpStatus.OK);
res.body.should.be.a("object");
res.body.responseCode.should.be.eq(httpStatus[ "200_NAME" ]);
res.body.should.have.property("result");
res.body.id.should.be.eq(routesConfig.config.datasource.save.api_id);
res.body.params.status.should.be.eq(constants.STATUS.SUCCESS)
res.body.result.message.should.be.eq(constants.RECORD_SAVED)
chai.spy.restore(dbConnector, "execute");
done();
});
})
})
describe("Datasource update API", () => {
it("should not update records in database", (done) => {
Expand Down Expand Up @@ -276,7 +296,7 @@ describe('Datasource APIS', () => {
done();
});
});

it("should not update records when request object does not contain required fields", (done) => {
chai.spy.on(ingestorService, "getDatasetConfig", () => {
return { "id": ":telemetry", "dataset_config": { "entry_topic": "telemetry" }, "router_config": { "topic": "telemetry" } }
Expand All @@ -296,7 +316,64 @@ describe('Datasource APIS', () => {
done();
});
});

it("should update datalake datasource", (done)=>{
chai.spy.on(dbConnector, "execute", () => {
return Promise.resolve([])
})
chai
.request(app)
.patch(config.apiDatasourceUpdateEndPoint)
.send(TestDataSource.VALID_DATALAKE_SCHEMA)
.end((err, res) => {
res.should.have.status(httpStatus.OK);
res.body.should.be.a("object");
res.body.responseCode.should.be.eq(httpStatus[ "200_NAME" ]);
res.body.should.have.property("result");
res.body.id.should.be.eq(routesConfig.config.datasource.update.api_id);
res.body.params.status.should.be.eq(constants.STATUS.SUCCESS)
res.body.result.message.should.be.eq(constants.RECORD_UPDATED)
chai.spy.restore(dbConnector, "execute");
done();
});
})
it("should not update records when given invalid schema in case of datalake", (done) => {
chai.spy.on(dbConnector, "execute", () => {
return Promise.resolve([])
})
chai
.request(app)
.patch(config.apiDatasourceUpdateEndPoint)
.send(TestDataSource.INVALID_DATALAKE_SCHEMA)
.end((err, res) => {
res.should.have.status(httpStatus.BAD_REQUEST);
res.body.should.be.a("object");
res.body.responseCode.should.be.eq(httpStatus[ "400_NAME" ]);
res.body.should.have.property("result");
res.body.id.should.be.eq(routesConfig.config.datasource.update.api_id);
res.body.params.status.should.be.eq(constants.STATUS.FAILURE)
chai.spy.restore(dbConnector, "execute");
done();
});
})
it("should handle case when table name is not passed", (done)=>{
chai.spy.on(dbConnector, "execute", () => {
return Promise.resolve([])
})
chai
.request(app)
.patch(config.apiDatasourceUpdateEndPoint)
.send(TestDataSource.UNDEFINED_TABLE)
.end((err, res) => {
res.should.have.status(httpStatus.OK);
res.body.should.be.a("object");
res.body.responseCode.should.be.eq(httpStatus[ "200_NAME" ]);
res.body.should.have.property("result");
res.body.id.should.be.eq(routesConfig.config.datasource.update.api_id);
res.body.params.status.should.be.eq(constants.STATUS.SUCCESS)
chai.spy.restore(dbConnector, "execute");
done();
});
})
})
describe("Datasource read API", () => {
it("should successfully retrieve records from database", (done) => {
Expand Down
Loading

0 comments on commit 6c15005

Please sign in to comment.