'use strict';

var setupFakeApi = function (fakeApiObject, options) {
  fakeApiObject.
    when(options.method, options.url).
    respond({});
};

describe('Service: Asana', function () {
  var fakeAsanaAPI;

  beforeEach(module('Asana'));

  beforeEach(inject(function ($injector) {
    fakeAsanaAPI = $injector.get('$httpBackend');
  }));

  afterEach(function () {
    fakeAsanaAPI.verifyNoOutstandingExpectation();
    fakeAsanaAPI.verifyNoOutstandingRequest();
  });

  describe('Task', function () {
    var Task;
    beforeEach(inject(function ($injector) {
      setupFakeApi(fakeAsanaAPI, { method: 'GET', url: 'https://app.asana.com/api/1.0/tasks'});
      Task = $injector.get('Task');
    }));

    describe('.get', function () {
      it('retrieves the tasks', function () {
        Task.get();
        fakeAsanaAPI.expectGET('https://app.asana.com/api/1.0/tasks');
        fakeAsanaAPI.flush();        
      });
    });
  });

  describe('Project', function () {
    var Project;
    beforeEach(inject(function ($injector) {
      setupFakeApi(fakeAsanaAPI, { method: 'GET', url: 'https://app.asana.com/api/1.0/projects/123/tasks' });
      setupFakeApi(fakeAsanaAPI, { method: 'GET', url: 'https://app.asana.com/api/1.0/projects/123' });
      Project = $injector.get('Project');
    }));

    describe('.get', function () {
      it('retrieves the project', function () {
        Project.get({projectId: 123});
        fakeAsanaAPI.expectGET('https://app.asana.com/api/1.0/projects/123');
        fakeAsanaAPI.flush();
      });
    });

    describe('.tasks', function() {
      it('retrieves the tasks in the project', function () {
        Project.tasks({projectId: 123});
        fakeAsanaAPI.expectGET('https://app.asana.com/api/1.0/projects/123/tasks');
        fakeAsanaAPI.flush();
      });
    });
  });

  describe('Tag', function () {
    var Tag;
    beforeEach(inject(function ($injector) {
      setupFakeApi(fakeAsanaAPI, { method: 'GET', url: 'https://app.asana.com/api/1.0/tags/123/tasks' });
      setupFakeApi(fakeAsanaAPI, { method: 'GET', url: 'https://app.asana.com/api/1.0/tags/123' });
      Tag = $injector.get('Tag');
    }));


    describe('.get', function () {
      it('retrieves the tag information', function () {
        Tag.get({tagId: 123});
        fakeAsanaAPI.expectGET('https://app.asana.com/api/1.0/tags/123');
        fakeAsanaAPI.flush();
      });
    });

    describe('.tasks', function() {
      it('retrieves the tasks in the tag', function () {
        Tag.tasks({tagId: 123});
        fakeAsanaAPI.expectGET('https://app.asana.com/api/1.0/tags/123/tasks');
        fakeAsanaAPI.flush();
      });
    });
  });

});


@@ -234,16 +234,107 @@
 na'));%0A%0A
+  beforeEach(module(function ($provide) %7B%0A    $provide.value('WORKSPACE_ID', 123);%0A  %7D));%0A%0A
   before
@@ -363,24 +363,28 @@
 $injector) %7B
+    
 %0A    fakeAsa
@@ -422,16 +422,51 @@
 kend');%0A
+    $injector.get('WORKSPACE_ID');%0A
   %7D));%0A%0A
@@ -538,24 +538,24 @@
 ectation();%0A
-
     fakeAsan
@@ -588,32 +588,573 @@
 quest();%0A  %7D);%0A%0A
+  describe('Workspace', function () %7B%0A    var Workspace;%0A    beforeEach(inject(function ($injector) %7B%0A      setupFakeApi(fakeAsanaAPI, %7Bmethod: 'GET', url: 'https://app.asana.com/api/1.0/workspaces/123/tags'%7D);%0A      Workspace = $injector.get('Workspace');%0A    %7D))%0A%0A    describe('.list', function () %7B%0A      it('retrieves a list of tags', function() %7B%0A        Workspace.get(%7Bpath: 'tags'%7D);%0A        fakeAsanaAPI.expectGET('https://app.asana.com/api/1.0/workspaces/123/tags');%0A        fakeAsanaAPI.flush();           %0A      %7D)%0A    %7D);%0A  %7D);%0A%0A
   describe('Task
@@ -2787,24 +2787,29 @@
 ags/123' %7D);
+     
 %0A      Tag =
@@ -2841,17 +2841,16 @@
   %7D));%0A%0A
-%0A
     desc

Add tests for the Workspace service.