var plague = require('../');
var test = require('tape')

//
// Register
//
test('testing register method', function(t) {
    var randomUser = {
        email: guid() + '@gmail.com',
        password: guid(),
        name: guid()
    }
    plague.register(randomUser.email, randomUser.password, randomUser.name, function(res) {
        if (res.error) {
            t.error(user.error, 'unable to create new user');
            return;
        }
        t.ok(res, 'user created');
        t.end();
        //
        // Login
        //
        t.test('testing login method', function(t) {
            plague.login(randomUser.email, randomUser.password, function(res) {
                if (res.error) {
                    t.error(user.error, 'unable to login');
                    return;
                }
                t.ok(res, 'login ok');
                t.end(res.error);
                //
                // Create Post
                //
                t.test('testing postText method', function(t) {
                    var postText = 'Hello Plague';
                    plague.postText(postText, function(res) {
                    	console.log(res);
                        t.equal(res.status, 'OK');
                        t.end(res.error);
                        //
                        // Get Posts
                        //			  	
                        t.test('testing getPosts method', function(t) {
                            plague.getPosts(function(res) {
                                var posts = res.posts;
                                console.log(posts);
                                t.equal(posts.length, 1);
                                t.equal(posts[0] ? posts[0].text : '', postText);
                                t.end();
                            });
                        })                                               
                    });

                })
            });
        });
    });


});




function guid() {
    function s4() {
        return Math.floor((1 + Math.random()) * 0x10000)
            .toString(16)
            .substring(1);
    }
    return s4() + s4() + s4() + s4() +
        s4() + s4() + s4() + s4();
}
@@ -1110,33 +1110,32 @@
  function(res) %7B
-%0A
                 
@@ -1143,25 +1143,8 @@
    %09
-console.log(res);
 %0A   
@@ -1516,17 +1516,16 @@
 s.posts;
-%0A
         
@@ -1552,27 +1552,8 @@
     
-console.log(posts);
 %0A   
@@ -1689,16 +1689,16 @@
 tText);%0A
-
         
@@ -1722,32 +1722,368 @@
        t.end();%0A
+                                t.test('testing deleteAllPosts method', function(t)%7B%0A                                %09 plague.deleteAllPosts(function(res)%7B%0A%09%09%09%09%09%09%09%09%09    plague.getPosts(function(res) %7B%0A%09%09%09%09%09%09%09%09%09    %09t.equal(posts.length, 0);%0A%09%09%09%09%09%09%09%09%09    %09t.end(res.end);%0A%09%09%09%09%09%09%09%09%09    %7D);%0A%09%09%09%09%09%09%09%09%09%7D);%0A                                %7D)%0A
                 

update tests