// group-api-test.js
//
// Test group API
//
// Copyright 2013, E14N https://e14n.com/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

var assert = require("assert"),
    vows = require("vows"),
    Step = require("step"),
    _ = require("underscore"),
    http = require("http"),
    urlparse = require("url").parse,
    httputil = require("./lib/http"),
    oauthutil = require("./lib/oauth"),
    actutil = require("./lib/activity"),
    pj = httputil.postJSON,
    gj = httputil.getJSON,
    validActivity = actutil.validActivity,
    setupApp = oauthutil.setupApp,
    newCredentials = oauthutil.newCredentials;

var suite = vows.describe("Group API test");

// A batch for testing the read-write access to the API

suite.addBatch({
    "When we set up the app": {
        topic: function() {
            setupApp(this.callback);
        },
        teardown: function(app) {
            if (app && app.close) {
                app.close();
            }
        },
        "it works": function(err, app) {
            assert.ifError(err);
        },
        "and we get make a new user": {
            topic: function() {
                newCredentials("fafhrd", "lankhmar+1", this.callback);
            },
            "it works": function(err, cred) {
                assert.ifError(err);
                assert.isObject(cred);
            },
            "and they create a group": {
                topic: function(cred) {
                    var callback = this.callback,
                        url = "http://localhost:4815/api/user/fafhrd/feed",
                        act = {
                            verb: "create",
                            object: {
                                objectType: "group",
                                displayName: "Barbarians"
                            }
                        };

                    pj(url, cred, act, function(err, data, resp) {
                        callback(err, data);
                    });
                },
                "it works": function(err, data) {
                    assert.ifError(err);
                    validActivity(data);
                }
            }
        }
    }
});

suite["export"](module);

@@ -1040,16 +1040,71 @@
 tivity,%0A
+    validActivityObject = actutil.validActivityObject,%0A
     setu
@@ -1130,16 +1130,16 @@
 tupApp,%0A
-
     newC
@@ -2341,16 +2341,112 @@
 barians%22
+,%0A                                summary: %22A safe place for barbarians to share their feelings%22
 %0A       
@@ -2734,32 +2734,32 @@
 t.ifError(err);%0A
-
                 
@@ -2779,24 +2779,792 @@
 vity(data);%0A
+                %7D,%0A                %22and we retrieve that group with the REST API%22: %7B%0A                    topic: function(act, cred) %7B%0A                        var callback = this.callback,%0A                            url = act.object.links.self.href;%0A%0A                        gj(url, cred, function(err, data, resp) %7B%0A                            callback(err, data);%0A                        %7D);%0A                    %7D,%0A                    %22it works%22: function(err, group) %7B%0A                        assert.ifError(err);%0A                        assert.isObject(group);%0A                    %7D,%0A                    %22it looks right%22: function(err, group) %7B%0A                        assert.ifError(err);%0A                        validActivityObject(group);%0A                    %7D%0A
             

Check that group was created