Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http requests always returns 404 #29

Open
digigarlab opened this issue Dec 10, 2018 · 2 comments · May be fixed by #31
Open

Http requests always returns 404 #29

digigarlab opened this issue Dec 10, 2018 · 2 comments · May be fixed by #31

Comments

@digigarlab
Copy link

Hi there,

I am basically writing a network adapter between two http APIs, and I want to write some integration tests.

For now I have a very simple flow with 2 nodes:

  • http in [POST /txmessage]
  • http out [statusCode = 204, body = ""]

That was pretty trivial to implement with node-red and it's working fine (I can query my node-red instance with CURL and get the 204 message). However when I try to test this with the node-red-node-test-helper I always get a 404.

Here is the code I used:

const test = require("ava");
const got = require("got");
const helper = require("node-red-node-test-helper");
const nodeDebug = require("node-red/nodes/core/core/58-debug");
const nodeHttpIn = require("node-red/nodes/core/io/21-httpin");
const nodeHttpReq = require("node-red/nodes/core/io/21-httprequest");

helper.init(require.resolve("node-red"));

test.before.cb(t => {
  helper.startServer(t.end);
});

test.after.cb("cleanup", t => {
  helper.stopServer(t.end);
});

test.afterEach.always(async t => {
  await helper.unload();
});

test.cb("txmessagestatus", t => {
  t.plan(2);

  var flow = [
    {
      id: "12d2f142.f5953f",
      type: "tab",
      label: "txmessagestatus",
      disabled: false,
      info: ""
    },
    {
      id: "c8f9f191.d37fe",
      type: "http in",
      z: "12d2f142.f5953f",
      name: "",
      url: "/txmessagestatus",
      method: "post",
      upload: false,
      swaggerDoc: "",
      x: 150.90908813476562,
      y: 118.18181610107422,
      wires: [["47b2e0e1.e1e37", "35170c4f.2aade4"]]
    },
    {
      id: "47b2e0e1.e1e37",
      type: "http response",
      z: "12d2f142.f5953f",
      name: "",
      statusCode: "204",
      headers: {},
      x: 384.5454559326172,
      y: 118.18181037902832,
      wires: []
    },
    {
      id: "35170c4f.2aade4",
      type: "debug",
      z: "12d2f142.f5953f",
      name: "",
      active: true,
      tosidebar: true,
      console: false,
      tostatus: false,
      complete: "false",
      x: 395.9090881347656,
      y: 189.9999942779541,
      wires: []
    }
  ];

  const nodes = [nodeHttpIn, nodeHttpReq, nodeDebug];

  helper.load(nodes, flow, async () => {
    const client = got.extend({
      headers: {
        "Content-Type": "application/json"
      }
    });

    try {
      const res = await client.post(helper.url() + "/txmessagestatus");
      t.is(res.statusCode, 204);
      t.is(res.body, "");
    } catch (err) {
      // Always fail here, statusCode = 404
      t.fail(err);
    } finally {
      t.end();
    }
  });
});

Do you have any idea why this is not working? I couldn't find any recipe of integration testing with node-red and http in/out online, it would be great if someone could point to a fix or suggest another approach. Thanks.

@Landry25
Copy link

Landry25 commented Feb 4, 2019

Hi,
I have the same issue by using the supertest API :
helper.request().get("/").expect(200).end(done);

I always get a 404 .

@HirokiUchikawa HirokiUchikawa linked a pull request Feb 12, 2019 that will close this issue
6 tasks
@axgkl
Copy link

axgkl commented Feb 24, 2020

same problem. how can we write integration tests involving NR's http in node?
The test http requests originate outside, e.g. from a python or go program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants