Skip to content

Commit

Permalink
Adds tests for absoluteURLs template lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmerfield committed Aug 29, 2019
1 parent 8c564d9 commit dca4aeb
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions app/blog/render/retrieve/tests/absoluteURLs.js
@@ -0,0 +1,54 @@
describe("absoluteURLs", function() {
var absoluteURLs = require("../absoluteURLs");
var mustache = require("mustache");

global.test.blog();

beforeEach(function() {
this.request = {
protocol: "http",
get: function() {
return "example.com";
}
};
});

it("replaces relative links with absolute URLs", function(done) {
var result;
var locals = {};
var html = '<a href="/foo"></a>';
var template = "{{#absoluteURLs}}" + html + "{{/absoluteURLs}}";

absoluteURLs(this.request, function(err, lambda) {
result = mustache.render(template, { absoluteURLs: lambda });
expect(result).toEqual('<a href="http://example.com/foo"></a>');
done();
});
});

it("replaces relative image sources with absolute sources", function(done) {
var result;
var locals = {};
var html = '<img src="/bar.jpg">';
var template = "{{#absoluteURLs}}" + html + "{{/absoluteURLs}}";

absoluteURLs(this.request, function(err, lambda) {
result = mustache.render(template, { absoluteURLs: lambda });
expect(result).toEqual('<img src="http://example.com/bar.jpg">');
done();
});
});

it("leaves fully qualified links and images as-is", function(done) {
var result;
var locals = {};
var html = '<a href="http://example.com/foo"><img src="http://example.com/bar.jpg"></a>';
var template = "{{#absoluteURLs}}" + html + "{{/absoluteURLs}}";

absoluteURLs(this.request, function(err, lambda) {
result = mustache.render(template, { absoluteURLs: lambda });
expect(result).toEqual(html);
done();
});
});
});

0 comments on commit dca4aeb

Please sign in to comment.