Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Does this project only work with APIs built in Node.js? #133

Closed
baynezy opened this issue Apr 20, 2017 · 9 comments
Closed

Does this project only work with APIs built in Node.js? #133

baynezy opened this issue Apr 20, 2017 · 9 comments

Comments

@baynezy
Copy link
Contributor

baynezy commented Apr 20, 2017

I wouldn't normally bug you with questions via GitHub issues, but I am struggling to find an answer to this question. I have searched high and low for an answer and have not managed to find a definitive conclusion.

This poor fellow asked about a year ago and suffered the fact that people didn't read his question. So I thought I would ask here as I didn't want to be another statistic on StackOverflow.

Thanks.

@noahdietz
Copy link
Contributor

Hey @baynezy, to be honest, I didn't know there were questions on SO regarding this project! I'll have to keep an eye out for those, thank you.

Simple answer: No, it is not exclusively for Node.js APIs.

Longer answer: The API doesn't have to be implemented in Node.js for a STT generated test to target it with an HTTP request. You have to use Node.js to utilize this module (obviously), but as long as you point the tests at a running server (localhost:1337, my.api.test.net) the implementation doesn't matter. The caveat here is that this module was designed to run with mocha which is a Node.js test runner/framework. So the tests have to be in a Node.js project, but the server implementation doesn't.

Does that clear things up? Thanks for the question.

@baynezy
Copy link
Contributor Author

baynezy commented Apr 20, 2017

@noahdietz - thanks that does clear things up. Thank you very much. I am fine with the testing application mandating Node.js. It is just that I want to test an API written in Java.

I do have one other question though. I might be being slow, but how do you point it at a particular host? None of the arguments seem to suggest that they do that.

@noahdietz
Copy link
Contributor

noahdietz commented Apr 20, 2017

I followed up on the SO question as well, thank you for bringing that to my attention.

The host is derived from your Swagger's global host property, at this line. As you can see, there is a default value of localhost:10010.

I realize that it isn't convenient to change this value whenever you want to test something, and an option to override this would be helpful.

@baynezy
Copy link
Contributor Author

baynezy commented Apr 20, 2017

@noahdietz - thanks. I also followed up on that SO post 😉 👍

So based on what you are saying if I am using swagger-test-templates as an NPM module then I need to make sure that my API I am testing is running on http://localhost:10010 ?

@noahdietz
Copy link
Contributor

Not quite. The default, if your Swagger spec does not contain a host value (see brief docs), is to use localhost:10010 in the generated test code as the hostname to target with a test. You can change it manually in the generated test files, but I realize that is annoying to do and an option to change this would be useful.

And just so I know we are on the same page, this module does not administer tests when it is run. STT only generates scaffolding test code for your API based on the Swagger, that then need to be written to file. (Not trying to be condescending, just want to make sure we are having the same conversation. The SO issue seemed to want a solution for administering tests. This is not that.)

Does that make more sense? Thanks for the patience.

@baynezy
Copy link
Contributor Author

baynezy commented Apr 20, 2017

@noahdietz - totally understand on the host issue.

On the other issue. What I want is something that will generate me some tests from a Swagger spec. So that I can get some coverage for free (or cheap) of the plumbing of HTTP of a REST API. So that I can concentrate on testing business logic. So I think we are on the same page.

@baynezy
Copy link
Contributor Author

baynezy commented Apr 20, 2017

For the host issue a work around is to do this:-

var swagger = require("./spec/swagger.json")
swagger.host = "some.other.api";

@noahdietz
Copy link
Contributor

@baynezy perfect, you are a prime user then 😄

That work around is definitely manageable. Good idea. If I get a free cycle or two, I might add a host option (trivial addition), and address some other ideas in a new minor release. But no promises... 😉

If you don't have anymore questions, feel free to close the issue. You can also hit me up/DM me on Twitter @no_d_here if you don't want to open an issue to ask a question. Thanks for using this and asking questions! Love to see this in use

@baynezy
Copy link
Contributor Author

baynezy commented Apr 21, 2017

Thanks for all your help @noahdietz

@baynezy baynezy closed this as completed Apr 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants