import {expect, assert} from 'chai';
import nock from 'nock';

import Classy from '../src/Classy';
import ClassyResource from '../src/ClassyResource';
import resources from '../src/resources';
import _ from 'lodash';

describe('ClassyResource', () => {
  let classy;

  beforeEach(() => {
    classy = new Classy({
      clientId: 'client_id_str',
      clientSecret: 'client_secret_str',
      requestDebug: false
    });
  });

  describe('createMethod', () => {

    it('should fail without required params', () => {
      const resource = new ClassyResource(classy, {
        path: '/test'
      });

      const method = resource.createMethod({
        path: '/{id}/test'
      });

      assert.throw(() => {
        method();
      }, Error);
    });

    it('should hit correct URL when called', () => {

      const resource = new ClassyResource(classy, {
        path: '/test'
      });

      const method = resource.createMethod({
        method: 'GET',
        path: '/{id}/test'
      });

      const result = { prop: true };

      const scope = nock('https://api.classy.org')
        .get('/2.0/test/1/test')
        .reply(200, result);

      method('1').then(function (response) {
        expect(response.prop).to.be.true;
      });

    });

    it('should choose app token when forced', () => {

      const resource = new ClassyResource(classy, {
        path: '/test'
      });
      const appToken = { token: 'app' };
      const memberToken = { token: 'member' };
      const tokenOpts = {
        member: memberToken,
        app: appToken,
        force: 'app'
      };
      const token = resource._chooseToken(tokenOpts);

      expect(token).to.equal(tokenOpts.app);

    });

    it('should choose member token when forced', () => {

      const resource = new ClassyResource(classy, {
        path: '/test'
      });
      const appToken = { token: 'app' };
      const memberToken = { token: 'member' };
      const tokenOpts = {
        member: memberToken,
        app: appToken,
        force: 'member'
      };
      const token = resource._chooseToken(tokenOpts);

      expect(token).to.equal(tokenOpts.member);
    });

    it('should choose `undefined` token when forced', () => {

      const resource = new ClassyResource(classy, {
        path: '/test'
      });
      const appToken = { token: 'app' };
      const memberToken = { token: 'member' };
      const tokenOpts = {
        member: memberToken,
        app: appToken,
        force: 'random!'
      };
      const token = resource._chooseToken(tokenOpts);

      expect(token).to.be.undefined;

    });

  });

});

@@ -258,16 +258,30 @@
 t classy
+,%0A    resource
 ;%0A%0A  bef
@@ -429,16 +429,89 @@
 %0A    %7D);
+%0A%0A    resource = new ClassyResource(classy, %7B%0A      path: '/test'%0A    %7D);
 %0A  %7D);%0A%0A
@@ -603,92 +603,8 @@
 =%3E %7B
-%0A      const resource = new ClassyResource(classy, %7B%0A        path: '/test'%0A      %7D);
 %0A%0A  
@@ -813,93 +813,8 @@
  %7B%0A%0A
-      const resource = new ClassyResource(classy, %7B%0A        path: '/test'%0A      %7D);%0A%0A
     
@@ -1166,32 +1166,74 @@
   %7D);%0A%0A    %7D);%0A%0A
+  %7D);%0A%0A  describe('_chooseToken', () =%3E %7B%0A
     it('should c
@@ -1275,92 +1275,8 @@
  %7B%0A%0A
-      const resource = new ClassyResource(classy, %7B%0A        path: '/test'%0A      %7D);%0A
     
@@ -1639,92 +1639,8 @@
  %7B%0A%0A
-      const resource = new ClassyResource(classy, %7B%0A        path: '/test'%0A      %7D);%0A
     
@@ -1972,425 +1972,1140 @@
 ose 
-%60undefined%60 token when forced', () =%3E %7B%0A%0A      const resource = new ClassyResource(classy, %7B%0A        path: '/test'%0A      %7D);%0A      const appToken = %7B token: 'app' %7D;%0A      const memberToken = %7B token: 'member' %7D;%0A      const tokenOpts = %7B%0A        member: memberToken,%0A        app: appToken,%0A        force: 'random!'%0A      %7D;%0A      const token = resource._chooseToken(tokenOpts);%0A%0A      expect(token).to.be.undefined;%0A
+member token if it exists & nothing is forced', () =%3E %7B%0A      const appToken = %7B token: 'app' %7D;%0A      const memberToken = %7B token: 'member' %7D;%0A      const tokenOpts = %7B%0A        member: memberToken,%0A        app: appToken,%0A      %7D;%0A%0A      const token = resource._chooseToken(tokenOpts);%0A%0A      expect(token).to.equal(tokenOpts.member);%0A    %7D);%0A%0A    it('should choose %60undefined%60 token when forced', () =%3E %7B%0A%0A      const appToken = %7B token: 'app' %7D;%0A      const memberToken = %7B token: 'member' %7D;%0A      const tokenOpts = %7B%0A        member: memberToken,%0A        app: appToken,%0A        force: 'random!'%0A      %7D;%0A      const token = resource._chooseToken(tokenOpts);%0A%0A      expect(token).to.be.undefined;%0A%0A    %7D);%0A  %7D);%0A%0A  describe('_generateAuthForm', () =%3E %7B%0A%0A    it('should generate an auth form from args', () =%3E %7B%0A      const authForm = resource._generateAuthForm(%5B%7B%0A        username: 'test',%0A        password: 'test'%0A      %7D%5D);%0A%0A      expect(authForm.client_id).to.equal(resource._classy.clientId);%0A      expect(authForm.client_secret).to.equal(resource._classy.clientSecret);%0A      expect(authForm.grant_type).to.equal('password');
 %0A   

Add testing for ClassyResource methods