First commit

This commit is contained in:
2021-03-07 05:58:59 +01:00
committed by Andreas Schaafsma
commit 6e1a5f9fe5
18475 changed files with 3309357 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package website.controller;
import website.controller.*;
import ufront.web.result.ViewResult;
import website.Server;
using tink.CoreApi;
// These imports are common for our various test-suite tools.
import buddy.*;
import mockatoo.Mockatoo.*;
import ufront.test.TestUtils.NaturalLanguageTests.*;
import utest.Assert;
using haxe.io.Path;
using buddy.Should;
using ufront.test.TestUtils;
using mockatoo.Mockatoo;
class DocumentationControllerTest extends BuddySuite {
public function new() {
var haxelibSite = WebsiteTests.getTestApp();
describe("When viewing documentation", {
it("Should load all pages without errors", function (done) {
var pages = DocumentationController.getDocumentationPages();
var allResults = [];
for ( url in pages.keys() ) {
var title = pages.get( url );
var page =
if ( url=="/documentation/" ) null
else url.substr( "/documentation/".length ).removeTrailingSlashes();
var result = whenIVisit( url )
.onTheApp( haxelibSite )
.itShouldLoad( DocumentationController, "documentationPage", [page] )
.itShouldReturn( ViewResult, function (result) {
Assert.same( TFromEngine("documentation/documentationPage"), result.templateSource );
Assert.same( TFromEngine("layout.html"), result.layoutSource );
(result.data['title']:String).should.be('$title - Haxelib Documentation');
});
allResults.push( result.result );
}
Future.ofMany( allResults ).handle( function() done() );
});
});
}
}

View File

@@ -0,0 +1,137 @@
package website.controller;
import website.api.ProjectListApi;
import website.controller.*;
import ufront.web.result.*;
import ufront.web.result.ViewResult;
import website.Server;
using tink.CoreApi;
import haxelib.server.SiteDb;
// These imports are common for our various test-suite tools.
import buddy.*;
import mockatoo.Mockatoo.*;
import ufront.test.TestUtils.NaturalLanguageTests.*;
import utest.Assert;
using buddy.Should;
using ufront.test.TestUtils;
using mockatoo.Mockatoo;
class HomeControllerTest extends BuddySuite {
public function new() {
var haxelibSite = WebsiteTests.getTestApp();
var mockApi = mock( ProjectListApi );
haxelibSite.injector.map( ProjectListApi ).toValue( mockApi );
mockApi.all().returns( Success(new List()) );
mockApi.byUser(cast anyString).returns( Success(new List()) );
mockApi.byTag(cast anyString).returns( Success(new List()) );
mockApi.search(cast anyString).returns( Success(new List()) );
mockApi.latest(cast anyInt).returns( Success(new List()) );
mockApi.getTagList(cast anyInt).returns( Success(new List()) );
describe("When I go to the homepage", {
it("Should show our homepage view", function (done) {
whenIVisit( "/" )
.onTheApp( haxelibSite )
.itShouldLoad( HomeController, "homepage", [] )
.itShouldReturn( ViewResult, function (result) {
var title:String = result.data['title'];
(result.data['title']:String).should.be("Haxelib - the Haxe package manager");
Assert.same( result.templateSource, TFromEngine("home/homepage") );
Assert.same( result.layoutSource, TFromEngine("layout.html") );
// TODO: check we have a list of popular projects
// TODO: check we have a list of recent projects
})
.andFinishWith( done );
});
// TODO: it("Show me my projects if I am logged in");
});
describe("When I load the tags page", {
it("Should show me a list of the most popular tags, sorted by popularity", function (done) {
whenIVisit( "/t/")
.onTheApp( haxelibSite )
.itShouldLoad( HomeController, "tagList", [] )
.itShouldReturn( ViewResult, function(result) {
Assert.same( result.templateSource, TFromEngine("home/tagList") );
Assert.same( result.layoutSource, TFromEngine("layout.html") );
// TODO: check that the tags are listed...
})
.andFinishWith( done );
});
});
describe("When I load a tag page", {
it("Should show the list of projects with that tag", function (done) {
whenIVisit( "/t/games")
.onTheApp( haxelibSite )
.itShouldLoad( HomeController, "tag", ["games"] )
.itShouldReturn( ViewResult, function(result) {
Assert.same( result.templateSource, TFromEngine("home/projectList.html") );
Assert.same( result.layoutSource, TFromEngine("layout.html") );
// TODO: check that the matching projects are correct
})
.andFinishWith( done );
});
});
describe("When I load the 'all projects' page", {
it("Should show them all", function (done) {
whenIVisit( "/all")
.onTheApp( haxelibSite )
.itShouldLoad( HomeController, "all", [] )
.itShouldReturn( ViewResult, function(result) {
Assert.same( result.templateSource, TFromEngine("home/projectList.html") );
Assert.same( result.layoutSource, TFromEngine("layout.html") );
// TODO: check that all projects are loaded
})
.andFinishWith( done );
});
});
describe("When I search", {
// TODO: ask Nicolas, should we just use Google?
// it("Should show me the search form if there is no search term entered");
// it("Should show projects matching the name");
// it("Should show projects matching the description");
// it("Redirect straight to the project page if there's only 1 search result");
});
describe("When I want to access the data through a JSON API", {
it("Should give me search via JSON", function (done) {
whenIVisit( "/search.json" )
.withTheQueryParams([ "v"=>"web" ])
.onTheApp( haxelibSite )
.itShouldLoad( HomeController, "searchJson", [{ v: "web" }] )
.itShouldReturn( JsonResult, function (result) {
// TODO: check the data is good.
// TODO: check the JSON is valid.
})
.andFinishWith( done );
});
it("Should give me tags via JSON", function (done) {
whenIVisit( "/t/games.json" )
.onTheApp( haxelibSite )
.itShouldLoad( HomeController, "tag", ["games.json"] )
.itShouldReturn( JsonResult, function (result) {
// TODO: check the data is good.
// TODO: check the JSON is valid.
})
.andFinishWith( done );
});
it("Should give me all via JSON", function (done) {
whenIVisit( "/all.json" )
.onTheApp( haxelibSite )
.itShouldLoad( HomeController, "allJson", [] )
.itShouldReturn( JsonResult, function (result) {
// TODO: check the data is good.
// TODO: check the JSON is valid.
})
.andFinishWith( done );
});
});
}
}

View File

@@ -0,0 +1,158 @@
package website.controller;
import haxe.io.Bytes;
import website.api.ProjectApi;
import website.controller.*;
import ufront.web.result.*;
import ufront.web.result.ViewResult;
import website.Server;
import haxe.ds.Option;
using tink.CoreApi;
// These imports are common for our various test-suite tools.
import buddy.*;
import mockatoo.Mockatoo.*;
import ufront.test.TestUtils.NaturalLanguageTests.*;
import utest.Assert;
using buddy.Should;
using ufront.test.TestUtils;
using mockatoo.Mockatoo;
class ProjectControllerTest extends BuddySuite {
public function new() {
var haxelibSite = WebsiteTests.getTestApp();
var mockApi = mock( ProjectApi );
haxelibSite.injector.map( ProjectApi ).toValue( mockApi );
mockApi.projectInfo(cast anyString).returns( Success({
name: "detox",
desc: "Detox Description",
website: "https://github.com/jasononeil/detox",
owner: "jason",
license: "MIT",
curversion: "1.0.0-rc.8",
versions: [{ date: "2010-01-01 34:56:12", name:"1.0.0-rc.8", downloads:150, comments:"Breaking changes everywhere." }],
tags: new List(),
}) );
mockApi.readContentFromZip(cast anyString, cast anyString, cast anyString).returns( Success(Some("content")) );
mockApi.readBytesFromZip(cast anyString, cast anyString, cast anyString).returns( Success(Some(Bytes.ofString(""))) );
mockApi.getInfoForPath(cast anyString, cast anyString, cast anyString).returns( Success(Binary(12)) );
describe("When I view a project", {
it("Should show the project view for the latest version", function (done) {
whenIVisit( "/p/detox" )
.onTheApp( haxelibSite )
.itShouldLoad( ProjectController, "project", ["detox"] )
.itShouldReturn( ViewResult, function (result) {
// TODO: Check we got the latest version.
// TODO: Check we got the correct project.
Assert.same( TFromEngine("project/version.html"), result.templateSource );
Assert.same( TFromEngine("layout.html"), result.layoutSource );
})
.andFinishWith( done );
});
});
describe("When I view a project version", {
var whenILoadAProjectVersion = whenIVisit( "/p/detox/1.0.0-rc.8/" ).onTheApp( haxelibSite );
it("Should load the correct layout / view", function (done) {
whenILoadAProjectVersion
.itShouldLoad( ProjectController, "version", ["detox","1.0.0-rc.8"] )
.itShouldReturn( ViewResult, function(result) {
Assert.same( TFromEngine("project/version.html"), result.templateSource );
Assert.same( TFromEngine("layout.html"), result.layoutSource );
}).andFinishWith( done );
});
it("Should show me the README for the current version", function (done) {
whenILoadAProjectVersion.itShouldReturn( ViewResult, function(result) {
// TODO: add appropriate tests here...
}).andFinishWith( done );
});
it("Should show me the file list for the current version", function (done) {
whenILoadAProjectVersion.itShouldReturn( ViewResult, function(result) {
// TODO: add appropriate tests here...
}).andFinishWith( done );
});
it("Should show me a list of all versions", function (done) {
whenILoadAProjectVersion.itShouldReturn( ViewResult, function(result) {
// TODO: add appropriate tests here...
}).andFinishWith( done );
});
it("Should show me the haxelibs this depends on", function (done) {
whenILoadAProjectVersion.itShouldReturn( ViewResult, function(result) {
// TODO: add appropriate tests here...
}).andFinishWith( done );
});
it("Should show me the haxelibs that depend on this", function (done) {
whenILoadAProjectVersion.itShouldReturn( ViewResult, function(result) {
// TODO: add appropriate tests here...
}).andFinishWith( done );
});
it("Should let me know if there is a more recent version", function (done) {
whenILoadAProjectVersion.itShouldReturn( ViewResult, function(result) {
// TODO: add appropriate tests here...
}).andFinishWith( done );
});
it("Should let me know if this version is not considered stable", function (done) {
whenILoadAProjectVersion.itShouldReturn( ViewResult, function(result) {
// TODO: add appropriate tests here...
}).andFinishWith( done );
});
});
describe("When I view a project's versions", {
it("Should show me a list of all the versions of that project, with the ability to show stable releases only.", function(done) {
whenIVisit( "/p/detox/versions" )
.onTheApp( haxelibSite )
.itShouldLoad( ProjectController, "versionList", ["detox"] )
.itShouldReturn( ViewResult, function (result) {
// TODO: Check it shows the list of versions.
})
.andFinishWith( done );
});
});
describe("When I view a project's files", {
it("Should show me that file's source code in line", function (done) {
whenIVisit( "/p/detox/1.0.0-rc.8/files/src/Detox.hx" )
.onTheApp( haxelibSite )
.itShouldLoad( ProjectController, "file", ["detox","1.0.0-rc.8",["src","Detox.hx"]] )
.itShouldReturn( ViewResult, function (result) {
// TODO: Check it shows the source code for the file.
})
.andFinishWith( done );
});
it("Should render markdown files as HTML", function (done) {
whenIVisit( "/p/detox/1.0.0-rc.8/files/README.md" )
.onTheApp( haxelibSite )
.itShouldLoad( ProjectController, "file", ["detox","1.0.0-rc.8",["README.md"]] )
.itShouldReturn( ViewResult, function (result) {
// TODO: Check it shows the rendered markdown.
})
.andFinishWith( done );
});
it("Should show binary files size and a link to download it", function (done) {
whenIVisit( "/p/hxssl/3.0.0-alpha/files/ndll/Linux64/hxssl.ndll" )
.onTheApp( haxelibSite )
.itShouldLoad( ProjectController, "file", ["hxssl","3.0.0-alpha",["ndll","Linux64","hxssl.ndll"]] )
.itShouldReturn( ViewResult, function (result) {
// TODO: Check it shows the file name and download size.
})
.andFinishWith( done );
});
});
describe("When I view a projects docs", {
it("Should show the correct documentation for this version", function(done) {
whenIVisit( "/p/detox/1.0.0-rc.8/doc/dtx.widget.Widget" )
.onTheApp( haxelibSite )
.itShouldLoad( ProjectController, "docs", ["detox","1.0.0-rc.8","dtx.widget.Widget"] )
.itShouldReturn( ViewResult, function (result) {
// TODO: Check it loads the correct view, documentation is rendered, etc.
})
.andFinishWith( done );
});
});
}
}

View File

@@ -0,0 +1,46 @@
package website.controller;
import website.controller.*;
import ufront.web.result.*;
import website.Server;
// These imports are common for our various test-suite tools.
import buddy.*;
import mockatoo.Mockatoo.*;
import ufront.test.TestUtils.NaturalLanguageTests.*;
import utest.Assert;
using buddy.Should;
using ufront.test.TestUtils;
using mockatoo.Mockatoo;
class RSSControllerTest extends BuddySuite {
public function new() {
var haxelibSite = WebsiteTests.getTestApp();
describe("When I try to view the RSS feed", {
it("Should give me some valid XML with the latest updates", function (done) {
whenIVisit( "/rss" )
.onTheApp( haxelibSite )
.itShouldLoad( RSSController, "rss", [{number:null}] )
.itShouldReturn( ContentResult, function (result) {
result.contentType.should.be( "text/xml" );
var rss = Xml.parse( result.content );
})
.andFinishWith( done );
});
it("Should let me set the number of entries to include", function (done) {
whenIVisit( "/rss" )
.withTheQueryParams([ "number"=>"3" ])
.onTheApp( haxelibSite )
.itShouldLoad( RSSController, "rss", [{number:3}] )
.itShouldReturn( ContentResult, function (result) {
result.contentType.should.be( "text/xml" );
var rss = Xml.parse( result.content );
// TODO: check that 3 results were loaded.
})
.andFinishWith( done );
});
});
}
}

View File

@@ -0,0 +1,73 @@
package website.controller;
import haxe.crypto.Md5;
import haxelib.server.SiteDb;
import website.controller.*;
import website.api.UserApi;
import ufront.web.result.*;
import ufront.web.result.ViewResult;
import website.Server;
using tink.CoreApi;
// These imports are common for our various test-suite tools.
import buddy.*;
import mockatoo.Mockatoo.*;
import ufront.test.TestUtils.NaturalLanguageTests.*;
import utest.Assert;
using buddy.Should;
using ufront.test.TestUtils;
using mockatoo.Mockatoo;
class UserControllerTest extends BuddySuite {
public function new() {
var haxelibSite = WebsiteTests.getTestApp();
var mockApi = mock( UserApi );
haxelibSite.injector.map( UserApi ).toValue( mockApi );
function mockUser(user,name,email) {
var u = new User();
u.name = user;
u.fullname = name;
u.email = email;
var hash = Md5.encode( email );
return { user:u, emailHash:hash, projects:[], totalDownloads:[] };
}
var user1 = mockUser( "jason", "Jason O'Neil", "jason@example.org" );
var user2 = mockUser( "ncanasse", "Nicolas Canasse", "nc@example.org" );
var projects = [];
mockApi.getUserProfile(cast anyString).returns( Success(new Pair(user1.user,[])) );
mockApi.getUserList().returns( Success([user1, user2]) );
describe("When I look at the profile of a user", {
it("Should show me that users profile and their projects", function (done) {
whenIVisit( "/u/jason" )
.onTheApp( haxelibSite )
.itShouldLoad( UserController, "profile", ["jason"] )
.itShouldReturn( ViewResult, function (result) {
var title:String = result.data['title'];
(result.data['title']:String).should.be("jason (Jason O'Neil) on Haxelib");
Assert.same( result.templateSource, TFromEngine("user/profile") );
Assert.same( result.layoutSource, TFromEngine("layout.html") );
})
.andFinishWith( done );
});
});
describe("When I want to see a list of users", {
it("Should show me that list, sorted by number of projects", function (done) {
whenIVisit( "/u" )
.onTheApp( haxelibSite )
.itShouldLoad( UserController, "list", [] )
.itShouldReturn( ViewResult, function (result) {
var title:String = result.data['title'];
(result.data['title']:String).should.be("Haxelib Contributors");
Assert.same( result.templateSource, TFromEngine("user/list") );
Assert.same( result.layoutSource, TFromEngine("layout.html") );
})
.andFinishWith( done );
});
});
}
}