示例#1
0
    it("SaveAndList a new low score", function(done) {
		
		var options = {
            // save params
            source: "localhost",
            points: 10000,
            playerid: "1",
            fields: {},
            playername: "ben",
            // list params
            table: "scores",
            lowest: true,
            perpage: 2,
            publickey: testgame.publickey
        };

        leaderboards.saveAndList(options, function(error, errorcode, numscores, scores) {
            assert.equal(error, null);
            assert.equal(errorcode, 0);
            assert.equal(numscores, 2);
            assert.equal(scores.length, 2);
            assert.equal(scores[0].points, 10000);
            assert.equal(scores[0].playername, "ben");
            assert.equal(scores[0].rank, 1);
            done();
        });
    });
示例#2
0
	it("List ranks match saveAndList", function(done) {
		
		var options = {
            // save params
            source: "localhost",
            points: 26500,
            playername: "random " + Math.random(),
			allowduplicates: true,
            // list params
            table: "scores",
			highest: true,
            perpage: 3,
            publickey: testgame.publickey
        };

        leaderboards.saveAndList(options, function(error, errorcode, numscores, scores) {
			
            assert.equal(error, null);
            assert.equal(errorcode, 0);
            assert.equal(numscores, 13);
			assert.equal(scores.length, 3);			
			assert.equal(scores[0].rank, 4);
			assert.equal(scores[1].rank, 5);
			assert.equal(scores[1].submitted, true);
			assert.equal(scores[2].rank, 6);

			options = {
	            table: "scores",
				highest: true,
	            perpage: 20,
	            publickey: testgame.publickey
			}
							
			leaderboards.list(options, function(error2, errorcode2, numscores2, scores2) {
								
	            assert.equal(error2, null);
	            assert.equal(errorcode2, 0);
	            assert.equal(numscores, numscores2);
				assert.equal(scores2.length, 13);

				// confirm the 3 scores we returned before match and are
				// really in the right rank and positions
				for(var i=3; i<6; i++)
				{
					assert.equal(scores[i - 3].scoreid, scores2[i].scoreid);
					assert.equal(scores[i - 3].rank, scores2[i].rank);
					assert.equal(scores[i - 3].playername, scores2[i].playername);
					assert.equal(scores[i - 3].points, scores2[i].points);
				}
				
				done();
			});        
        });
	});
示例#3
0
    it("SaveAndList a new high score", function(done) {
		
		var options = {

            // save params
            source: "localhost",
            points: 12000,
            playerid: "11",
            fields: {
                age: 1
            },
            playername: "isabella",

            // list params
            table: "scores",
            highest: true,
            perpage: 10,
            publickey: testgame.publickey,
            filters: {
                age: 1
            }
        };
		
        leaderboards.saveAndList(options, function(error, errorcode, numscores, scores) {
            assert.equal(error, null);
            assert.equal(errorcode, 0);
            assert.equal(numscores, 1);
            assert.equal(scores.length, 1);

            // one of the scores should be the saved one
            for(var i=0; i<10; i++) {

                if(scores[i].playername == "isabella") {
                    assert.equal(scores[i].points, 12000);
                    assert.equal(scores[i].fields.age, 1);
                    assert.equal(scores[i].playername, "isabella");
                    done();
					return;
                }
            }
			
			assert.equal(1, 2);
			done();
        });
    });