Skip to content

Commit

Permalink
Added to tests and README
Browse files Browse the repository at this point in the history
  • Loading branch information
ParadigmZero committed Jun 14, 2023
1 parent 2d40a62 commit a72d693
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,27 @@ Run as follows:

`newman run WebpageWordCounter.postman_collection.json`

You can also test the endpoints individually as so:
Further options:

`newman run WebpageWordCounter.postman_collection.json --folder wordcount`
- change `base_url` (the default is <http://localhost:4000>). Example:

`newman run WebpageWordCounter.postman_collection.json --folder dynamicwordcount`
`--env-var "base_url=https://webpagewordcount.onrender.com"`

- test a single endpoint. Endpoints are organized in folders in the collection. Folder names correspond to endpoint names, and so you can specify which endpoint to test as follows:

`--folder dynamicwordcount`

Sample run:

`newman run WebpageWordCounter.postman_collection.json --env-var "base_url=https://webpagewordcount.onrender.com" --folder wordcount`

# Deployment ( as of date of this README publication )

Dockerized application has a free-tier deployment with `Render.com` at the following URL.

<https://webpagewordcount.onrender.com>

The Master branch is automatically deployed there.

# Development related

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export function getEmbeddedPageUrls(body : string) : string[] {
* @param url - string of url
* @returns the url with http:// appended if necessary
*/
function addHTTPtoUrl(url : string) : string
export function addHTTPtoUrl(url : string) : string
{
if(url.substring(0,7).toLowerCase() !== 'http://'
&&
Expand Down Expand Up @@ -349,4 +349,4 @@ export function urlResolver(originalUrl : string, newUrl : string) : string {
}


module.exports = {app, openapiSpecification, wordCount, getEmbeddedPageUrls, urlResolver, dynamicWordCount};
module.exports = {app, wordCount, dynamicWordCount, addHTTPtoUrl, getEmbeddedPageUrls, urlResolver};
8 changes: 7 additions & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import {urlResolver, getEmbeddedPageUrls, wordCount, dynamicWordCount} from "../src/index";
import {urlResolver, addHTTPtoUrl, getEmbeddedPageUrls, wordCount, dynamicWordCount} from "../src/index";

test("urls are properly resolved (with base url) in the urlResolver method", () => {
expect(urlResolver("http://www.mydomain.com/","./dir/mypage.html")).toEqual("http://www.mydomain.com/dir/mypage.html");
expect(urlResolver("http://www.mydomain.com/","mypage.html")).toEqual("http://www.mydomain.com/mypage.html");
expect(urlResolver("http://www.mydomain.com/","http://www.adifferentsite.com")).toEqual("http://www.adifferentsite.com");
});

test("Add http:// to urls where appropriate in addHTTPtoUrl method", () => {
expect(addHTTPtoUrl("google.com" as string)).toEqual("http://google.com");
expect(addHTTPtoUrl("http://google.com" as string)).toEqual("http://google.com");
expect(addHTTPtoUrl("https://google.com" as string)).toEqual("https://google.com");
});

test("The getEmbeddedPageUrls function should extract the url from embedded content tags", () => {
expect(getEmbeddedPageUrls(`
<html>
Expand Down

0 comments on commit a72d693

Please sign in to comment.