Fixed mocking for last test
This commit is contained in:
@@ -168,7 +168,6 @@ class RemoteHandler {
|
|||||||
|
|
||||||
// REVISIT: How to call service datasource w/o handlers
|
// REVISIT: How to call service datasource w/o handlers
|
||||||
// REVISIT: const result = await targetService.read(target).columns(req.query.SELECT.columns).where({ [targetKeyFieldName]: entry[keyFieldName] });
|
// REVISIT: const result = await targetService.read(target).columns(req.query.SELECT.columns).where({ [targetKeyFieldName]: entry[keyFieldName] });
|
||||||
// TODO: Seems not to respect filter for targetkeyFieldName
|
|
||||||
const selectTarget = SELECT(req.query.SELECT.columns)
|
const selectTarget = SELECT(req.query.SELECT.columns)
|
||||||
.from(target)
|
.from(target)
|
||||||
.where({ [targetKeyFieldName]: entry[keyFieldName] });
|
.where({ [targetKeyFieldName]: entry[keyFieldName] });
|
||||||
|
|||||||
@@ -109,6 +109,16 @@ const NotesExpandSuppliers = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const BPMock = {
|
||||||
|
url: /.*/,
|
||||||
|
data: BPs
|
||||||
|
};
|
||||||
|
|
||||||
|
const BP11Mock = {
|
||||||
|
url: /\/A_BusinessPartner\?.*\$filter=BusinessPartner%20eq%20%2711%27/,
|
||||||
|
data: [ BPs[0] ]
|
||||||
|
};
|
||||||
|
|
||||||
class MockServer {
|
class MockServer {
|
||||||
async start() {
|
async start() {
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
@@ -116,13 +126,29 @@ class MockServer {
|
|||||||
this.app = express();
|
this.app = express();
|
||||||
this.server = http.createServer(this.app).listen();
|
this.server = http.createServer(this.app).listen();
|
||||||
this.app.set('port', this.server.address().port);
|
this.app.set('port', this.server.address().port);
|
||||||
|
this.mocks = [];
|
||||||
|
|
||||||
this.app.get("*", (req, res) => {
|
this.app.get("*", (req, res) => {
|
||||||
|
const mock = this.mocks.shift();
|
||||||
|
if (!mock || !req.url.match(mock.url)) {
|
||||||
|
res.writeHead(404);
|
||||||
|
res.end();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.end(JSON.stringify(BPs));
|
res.end(JSON.stringify(mock.data));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
this.mocks = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
add(mock) {
|
||||||
|
this.mocks.push(mock);
|
||||||
|
}
|
||||||
|
|
||||||
url() {
|
url() {
|
||||||
return `http://localhost:${this.server.address().port}`;
|
return `http://localhost:${this.server.address().port}`;
|
||||||
}
|
}
|
||||||
@@ -155,6 +181,10 @@ describe("Notes", () => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach( () => {
|
||||||
|
mockServer.reset();
|
||||||
|
});
|
||||||
|
|
||||||
const { expect, GET, PATCH } = require(".").run(
|
const { expect, GET, PATCH } = require(".").run(
|
||||||
"serve",
|
"serve",
|
||||||
"--project",
|
"--project",
|
||||||
@@ -193,6 +223,7 @@ describe("Notes", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("get remote suppliers", async () => {
|
it("get remote suppliers", async () => {
|
||||||
|
mockServer.add(BPMock);
|
||||||
const { status, data } = await GET("/notes/Suppliers");
|
const { status, data } = await GET("/notes/Suppliers");
|
||||||
|
|
||||||
expect({ status, data }).to.containSubset({
|
expect({ status, data }).to.containSubset({
|
||||||
@@ -202,6 +233,7 @@ describe("Notes", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("get remote suppliers with notes", async () => {
|
it("get remote suppliers with notes", async () => {
|
||||||
|
mockServer.add(BPMock);
|
||||||
const { status, data } = await GET("/notes/Suppliers?$expand=notes");
|
const { status, data } = await GET("/notes/Suppliers?$expand=notes");
|
||||||
|
|
||||||
expect({ status, data }).to.containSubset({
|
expect({ status, data }).to.containSubset({
|
||||||
@@ -211,6 +243,7 @@ describe("Notes", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("get notes via navigation", async () => {
|
it("get notes via navigation", async () => {
|
||||||
|
mockServer.add(BPMock);
|
||||||
const { status, data } = await GET("/notes/Suppliers('11')/notes");
|
const { status, data } = await GET("/notes/Suppliers('11')/notes");
|
||||||
|
|
||||||
expect({ status, data }).to.containSubset({
|
expect({ status, data }).to.containSubset({
|
||||||
@@ -220,6 +253,7 @@ describe("Notes", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("get notes with suppliers", async () => {
|
it("get notes with suppliers", async () => {
|
||||||
|
mockServer.add(BPMock);
|
||||||
const { status, data } = await GET("/notes/Notes?$expand=supplier");
|
const { status, data } = await GET("/notes/Notes?$expand=supplier");
|
||||||
|
|
||||||
expect({ status, data }).to.containSubset({
|
expect({ status, data }).to.containSubset({
|
||||||
@@ -228,18 +262,14 @@ describe("Notes", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: Seems not to respect filter for targetKeyFieldName
|
it("get supplier via navigation", async () => {
|
||||||
/*
|
mockServer.add(BP11Mock);
|
||||||
|
const { status, data } = await GET(`/notes/Notes(${ NotesExpandSuppliers[1].ID })/supplier`);
|
||||||
it.only("get supplier via navigation", async () => {
|
|
||||||
const { status, data } = await GET("/notes/Notes(545A3CF9-84CF-46C8-93DC-E29F0F2BC6BE)/supplier");
|
|
||||||
expect({ status, data }).to.containSubset({
|
expect({ status, data }).to.containSubset({
|
||||||
status: 200,
|
status: 200,
|
||||||
data: envelope("Suppliers", NotesExpandSuppliers[0].supplier )
|
data: envelope("../$metadata#Suppliers/$entity", NotesExpandSuppliers[1].supplier )
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
|
afterAll(() => mockServer.close());
|
||||||
after(() => mockServer.close());
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user