| 1 |
package website.controller; |
| 2 |
|
| 3 |
import haxe.crypto.Md5; |
| 4 |
import haxelib.server.SiteDb; |
| 5 |
import website.controller.*; |
| 6 |
import website.api.UserApi; |
| 7 |
import ufront.web.result.*; |
| 8 |
import ufront.web.result.ViewResult; |
| 9 |
import website.Server; |
| 10 |
using tink.CoreApi; |
| 11 |
|
| 12 |
// These imports are common for our various test-suite tools. |
| 13 |
import buddy.*; |
| 14 |
import mockatoo.Mockatoo.*; |
| 15 |
import ufront.test.TestUtils.NaturalLanguageTests.*; |
| 16 |
import utest.Assert; |
| 17 |
using buddy.Should; |
| 18 |
using ufront.test.TestUtils; |
| 19 |
using mockatoo.Mockatoo; |
| 20 |
|
| 21 |
class UserControllerTest extends BuddySuite { |
| 22 |
public function new() { |
| 23 |
|
| 24 |
var haxelibSite = WebsiteTests.getTestApp(); |
| 25 |
var mockApi = mock( UserApi ); |
| 26 |
haxelibSite.injector.map( UserApi ).toValue( mockApi ); |
| 27 |
|
| 28 |
function mockUser(user,name,email) { |
| 29 |
var u = new User(); |
| 30 |
u.name = user; |
| 31 |
u.fullname = name; |
| 32 |
u.email = email; |
| 33 |
var hash = Md5.encode( email ); |
| 34 |
return { user:u, emailHash:hash, projects:[], totalDownloads:[] }; |
| 35 |
} |
| 36 |
var user1 = mockUser( "jason", "Jason O'Neil", "[email protected]" ); |
| 37 |
var user2 = mockUser( "ncanasse", "Nicolas Canasse", "[email protected]" ); |
| 38 |
var projects = []; |
| 39 |
|
| 40 |
mockApi.getUserProfile(cast anyString).returns( Success(new Pair(user1.user,[])) ); |
| 41 |
mockApi.getUserList().returns( Success([user1, user2]) ); |
| 42 |
|
| 43 |
describe("When I look at the profile of a user", { |
| 44 |
it("Should show me that users profile and their projects", function (done) { |
| 45 |
whenIVisit( "/u/jason" ) |
| 46 |
.onTheApp( haxelibSite ) |
| 47 |
.itShouldLoad( UserController, "profile", ["jason"] ) |
| 48 |
.itShouldReturn( ViewResult, function (result) { |
| 49 |
var title:String = result.data['title']; |
| 50 |
(result.data['title']:String).should.be("jason (Jason O'Neil) on Haxelib"); |
| 51 |
Assert.same( result.templateSource, TFromEngine("user/profile") ); |
| 52 |
Assert.same( result.layoutSource, TFromEngine("layout.html") ); |
| 53 |
}) |
| 54 |
.andFinishWith( done ); |
| 55 |
}); |
| 56 |
}); |
| 57 |
|
| 58 |
describe("When I want to see a list of users", { |
| 59 |
it("Should show me that list, sorted by number of projects", function (done) { |
| 60 |
whenIVisit( "/u" ) |
| 61 |
.onTheApp( haxelibSite ) |
| 62 |
.itShouldLoad( UserController, "list", [] ) |
| 63 |
.itShouldReturn( ViewResult, function (result) { |
| 64 |
var title:String = result.data['title']; |
| 65 |
(result.data['title']:String).should.be("Haxelib Contributors"); |
| 66 |
Assert.same( result.templateSource, TFromEngine("user/list") ); |
| 67 |
Assert.same( result.layoutSource, TFromEngine("layout.html") ); |
| 68 |
}) |
| 69 |
.andFinishWith( done ); |
| 70 |
}); |
| 71 |
}); |
| 72 |
} |
| 73 |
} |