Skip to content

Commit

Permalink
Merge pull request #220 from Rakshitha-D/connector_list
Browse files Browse the repository at this point in the history
#OBS-I142: added test cases for connector list
  • Loading branch information
HarishGangula authored Jul 31, 2024
2 parents 48fb3ff + a700cb0 commit 1b142d2
Show file tree
Hide file tree
Showing 2 changed files with 430 additions and 0 deletions.
132 changes: 132 additions & 0 deletions api-service/src/tests/Connectors/ConnectorsList/ConnectorsList.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import app from "../../../app";
import chai, { expect } from "chai";
import chaiHttp from "chai-http";
import spies from "chai-spies";
import httpStatus from "http-status";
import { describe, it } from "mocha";
import { TestInputsForConnectorsList } from "./Fixtures";
import { ConnectorRegistry } from "../../../models/ConnectorRegistry";

chai.use(spies);
chai.should();
chai.use(chaiHttp);

const apiId = "api.connectors.list"
const msgid = "4a7f14c3-d61e-4d4f-be78-181834eeff6d"


describe("Connector List Api", () => {
afterEach(() => {
chai.spy.restore();
});

it("Connectors list Success: With all the filters provided", (done) => {
chai.spy.on(ConnectorRegistry, "findAll", () => {
return Promise.resolve([TestInputsForConnectorsList.VALID_CONNECTORS_LIST])
})
chai
.request(app)
.post("/v2/connectors/list")
.send(TestInputsForConnectorsList.REQUEST_WITH_BOTH_FILTERS)
.end((err, res) => {
res.should.have.status(httpStatus.OK);
res.body.should.be.a("object")
res.body.id.should.be.eq(apiId);
res.body.params.status.should.be.eq("SUCCESS")
res.body.result.should.be.a("object")
res.body.result.count.should.be.eq(1)
res.body.params.msgid.should.be.eq(msgid)
const result = JSON.stringify(res.body.result.data)
const expectedResult = JSON.stringify([TestInputsForConnectorsList.VALID_CONNECTORS_LIST])
result.should.be.eq(expectedResult)
done();
});
})

it("Connectors list Success: Without filters", (done) => {
chai.spy.on(ConnectorRegistry, "findAll", () => {
return Promise.resolve([TestInputsForConnectorsList.VALID_CONNECTORS_LIST])
})
chai
.request(app)
.post("/v2/connectors/list")
.send(TestInputsForConnectorsList.REQUEST_WITHOUT_FILTERS)
.end((err, res) => {
res.should.have.status(httpStatus.OK);
res.body.should.be.a("object")
res.body.id.should.be.eq(apiId);
res.body.params.status.should.be.eq("SUCCESS")
res.body.result.should.be.a("object")
res.body.result.count.should.be.eq(1)
res.body.params.msgid.should.be.eq(msgid)
const result = JSON.stringify(res.body.result.data)
const expectedResult = JSON.stringify([TestInputsForConnectorsList.VALID_CONNECTORS_LIST])
result.should.be.eq(expectedResult)
done();
});
})

it("Connectors list Success: Filtered based on category", (done) => {
chai.spy.on(ConnectorRegistry, "findAll", () => {
return Promise.resolve([TestInputsForConnectorsList.VALID_CONNECTORS_LIST_CATEGORY])
})
chai
.request(app)
.post("/v2/connectors/list")
.send(TestInputsForConnectorsList.REQUEST_WITH_CATEGORY_FILTERS)
.end((err, res) => {
res.should.have.status(httpStatus.OK);
res.body.should.be.a("object")
res.body.id.should.be.eq(apiId);
res.body.params.status.should.be.eq("SUCCESS")
res.body.result.should.be.a("object")
res.body.result.count.should.be.eq(1)
res.body.params.msgid.should.be.eq(msgid)
const result = JSON.stringify(res.body.result.data)
const expectedResult = JSON.stringify([TestInputsForConnectorsList.VALID_CONNECTORS_LIST_CATEGORY])
result.should.be.eq(expectedResult)
done();
});
})

it("Connectors list Success: Filtered based on status", (done) => {
chai.spy.on(ConnectorRegistry, "findAll", () => {
return Promise.resolve([TestInputsForConnectorsList.VALID_CONNECTORS_LIST_STATUS])
})
chai
.request(app)
.post("/v2/connectors/list")
.send(TestInputsForConnectorsList.REQUEST_WITH_STATUS_FILTERS)
.end((err, res) => {
res.should.have.status(httpStatus.OK);
res.body.should.be.a("object")
res.body.id.should.be.eq(apiId);
res.body.params.status.should.be.eq("SUCCESS")
res.body.result.should.be.a("object")
res.body.result.count.should.be.eq(1)
res.body.params.msgid.should.be.eq(msgid)
const result = JSON.stringify(res.body.result.data)
const expectedResult = JSON.stringify([TestInputsForConnectorsList.VALID_CONNECTORS_LIST_STATUS])
result.should.be.eq(expectedResult)
done();
});
})

it("Connectors list failure: Invalid request payload provided", (done) => {
chai
.request(app)
.post("/v2/connectors/list")
.send(TestInputsForConnectorsList.INVALID_REQUEST)
.end((err, res) => {
res.should.have.status(httpStatus.BAD_REQUEST);
res.body.should.be.a("object")
res.body.id.should.be.eq(apiId);
res.body.params.status.should.be.eq("FAILED")
res.body.error.code.should.be.eq("CONNECTORS_LIST_INPUT_INVALID")
expect(res.body.error.message).to.match(/^(.+) must NOT have fewer than 1 items$/)
done();
});
});


})
Loading

0 comments on commit 1b142d2

Please sign in to comment.