Commit fc0c69287069af9a47176abb1488f653f91eebdb

Authored by Christian Simon
1 parent 8edc6b6a

Add docs/tests for groups api

doc/api/README.md
... ... @@ -32,6 +32,7 @@ When listing resources you can pass the following parameters:
32 32 + [Users](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/users.md)
33 33 + [Session](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/session.md)
34 34 + [Projects](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/projects.md)
  35 ++ [Groups](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/groups.md)
35 36 + [Snippets](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/snippets.md)
36 37 + [Repositories](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/repositories.md)
37 38 + [Issues](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/issues.md)
... ...
doc/api/groups.md 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +## List project groups
  2 +
  3 +Get a list of groups. (As user: my groups, as admin: all groups)
  4 +
  5 +```
  6 +GET /groups
  7 +```
  8 +
  9 +```json
  10 +[
  11 + {
  12 + "id": 1,
  13 + "name": "Foobar Group",
  14 + "path": "foo-bar",
  15 + "owner_id": 18
  16 + }
  17 +]
  18 +```
  19 +
  20 +## Details of group
  21 +
  22 +Get all details of a group.
  23 +
  24 +```
  25 +GET /groups/:id
  26 +```
  27 +
  28 +Parameters:
  29 +
  30 ++ `id` (required) - The ID of a group
  31 +
  32 +## New group
  33 +
  34 +Create a new project group. Available only for admin
  35 +
  36 +```
  37 +POST /groups
  38 +```
  39 +
  40 +Parameters:
  41 ++ `name` (required) - Email
  42 ++ `path` - Password
  43 +
  44 +Will return created group with status `201 Created` on success, or `404 Not found` on fail.
  45 +
... ...
spec/requests/api/groups_spec.rb 0 → 100644
... ... @@ -0,0 +1,88 @@
  1 +require 'spec_helper'
  2 +
  3 +describe Gitlab::API do
  4 + include ApiHelpers
  5 +
  6 + let(:user1) { create(:user) }
  7 + let(:user2) { create(:user) }
  8 + let(:admin) { create(:admin) }
  9 + let!(:group1) { create(:group, owner: user1) }
  10 + let!(:group2) { create(:group, owner: user2) }
  11 +
  12 + describe "GET /groups" do
  13 + context "when unauthenticated" do
  14 + it "should return authentication error" do
  15 + get api("/groups")
  16 + response.status.should == 401
  17 + end
  18 + end
  19 +
  20 + context "when authenticated as user" do
  21 + it "normal user: should return an array of groups of user1" do
  22 + get api("/groups", user1)
  23 + response.status.should == 200
  24 + json_response.should be_an Array
  25 + json_response.length.should == 1
  26 + json_response.first['name'].should == group1.name
  27 + end
  28 + end
  29 +
  30 + context "when authenticated as admin" do
  31 + it "admin: should return an array of all groups" do
  32 + get api("/groups", admin)
  33 + response.status.should == 200
  34 + json_response.should be_an Array
  35 + json_response.length.should == 2
  36 + end
  37 + end
  38 + end
  39 +
  40 + describe "GET /groups/:id" do
  41 + context "when authenticated as user" do
  42 + it "should return one of user1's groups" do
  43 + get api("/groups/#{group1.id}", user1)
  44 + response.status.should == 200
  45 + json_response['name'] == group1.name
  46 + end
  47 +
  48 + it "should not return a non existing group" do
  49 + get api("/groups/1328", user1)
  50 + response.status.should == 404
  51 + end
  52 +
  53 + it "should not return a group not attached to user1" do
  54 + get api("/groups/#{group2.id}", user1)
  55 + response.status.should == 404
  56 + end
  57 + end
  58 +
  59 + context "when authenticated as admin" do
  60 + it "should return any existing group" do
  61 + get api("/groups/#{group2.id}", admin)
  62 + response.status.should == 200
  63 + json_response['name'] == group2.name
  64 + end
  65 +
  66 + it "should not return a non existing group" do
  67 + get api("/groups/1328", admin)
  68 + response.status.should == 404
  69 + end
  70 + end
  71 + end
  72 +
  73 + describe "POST /groups" do
  74 + context "when authenticated as user" do
  75 + it "should not create group" do
  76 + post api("/groups", user1), attributes_for(:group)
  77 + response.status.should == 403
  78 + end
  79 + end
  80 +
  81 + context "when authenticated as admin" do
  82 + it "should create group" do
  83 + post api("/groups", admin), attributes_for(:group)
  84 + response.status.should == 201
  85 + end
  86 + end
  87 + end
  88 +end
... ...