// user-api-test.js
//
// Test the client registration API
//
// Copyright 2012, StatusNet Inc.
//
// 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'),
    httputil = require('./lib/http');

var suite = vows.describe('user API');

suite.addBatch({
    'When we set up the app': {
        topic: function() {
            var cb = this.callback,
                config = {port: 4815,
                          hostname: 'localhost',
                          driver: 'memory',
                          params: {},
                          nologger: true
                         },
                makeApp = require('../lib/app').makeApp;

            makeApp(config, function(err, app) {
                if (err) {
                    cb(err, null);
                } else {
                    app.run(function(err) {
                        if (err) {
                            cb(err, null);
                        } else {
                            cb(null, app);
                        }
                    });
                }
            });
        },
        teardown: function(app) {
            app.close();
        },
        'it works': function(err, app) {
            assert.ifError(err);
        },
        'and we check the user list endpoint': {
            topic: function() {
                httputil.options('localhost', 4815, '/api/users', this.callback);
            },
            'it exists': function(err, allow, res, body) {
                assert.ifError(err);
                assert.equal(res.statusCode, 200);
            },
            'it supports GET': function(err, allow, res, body) {
                assert.include(allow, 'GET');
            },
            'it supports POST': function(err, allow, res, body) {
                assert.include(allow, 'GET');
            }
        }
    }
});

suite.export(module);
@@ -2423,32 +2423,939 @@
 ;%0A            %7D%0A
+        %7D,%0A        'and we create a client using the api': %7B%0A            topic: function() %7B%0A                var cb = this.callback;%0A                httputil.post('localhost', 4815, '/api/client/register', %7Btype: 'client_associate'%7D, function(err, res, body) %7B%0A                    var cl;%0A                    if (err) %7B%0A                        cb(err, null);%0A                    %7D else %7B%0A                        try %7B%0A                            cl = JSON.parse(body);%0A                            cb(null, cl);%0A                        %7D catch (err) %7B%0A                            cb(err, null);%0A                        %7D%0A                    %7D%0A                %7D);%0A            %7D,%0A            'it works': function(err, cl) %7B%0A                assert.ifError(err);%0A                assert.isObject(cl);%0A                assert.isString(cl.client_id);%0A                assert.isString(cl.client_secret);%0A            %7D%0A
         %7D%0A    %7D%0A

add a client in user-api