 firehoseTest 'Fetch Based on KB subdomain', 3, (agent) ->
   company = agent.companies[0]
   company.fetch()
-  .done (data, companyFetchTextStatus) ->
+  .done ->
     kbCompany = Firehose.Company.companyWithKBSubdomain company.knowledgeBaseSubdomain
     kbCompany.fetch()
-    .done (data, kbFetchTextStatus) ->
+    .done (data, textStatus) ->
+      equal textStatus, "success"
+      ok company.id?
+      ok company.title?
+      start()
+    .fail ->
+      start()
+  .fail ->
+    start()
+
+firehoseTest 'Fetch Based on KB custom domain', 3, (agent) ->
+  company = agent.companies[0]
+  company.fetch()
+  .done ->
+    kbCompany = Firehose.Company.companyWithKBCustomDomain company.knowledgeBaseCustomDomain
+    kbCompany.fetch()
+    .done (data, textStatus) ->
       equal kbFetchTextStatus, "success"
       ok company.id?
       ok company.title?

    equal textStatus, "success"
    ok articles.length > 0
    start()
  .fail (jqXHR, textStatus, errorThrown) ->
    start()

firehoseTest 'Search Articles', 2, (agent) ->
  company = agent.companies[0]
  articles = company.articles()
  articles.next()
  .done (data, articlesNextTextStatus) ->
    firstWord = articles[0].body.split(" ")[0]
    searchedArticles = company.searchedArticles firstWord
    searchedArticles.next()
    .done (data, searchedArticlesNextTextStatus) ->
      equal searchedArticlesNextTextStatus, "success"
      ok searchedArticles.length > 0
      start()
    .fail (jqXHR, searchedArticlesNextTextStatus, errorThrown) ->
      start()
  .fail (jqXHR, articlesNextTextStatus, errorThrown) ->
    start()

firehoseTest 'Search Articles (Abort)', 1, (agent) ->
  company = agent.companies[0]
  articles = company.articles()
  articles.next()
  .done (data, articlesNextTextStatus) ->
    firstWord = articles[0].body.split(" ")[0]
    searchedArticles = company.searchedArticles firstWord
    searchedArticles.next()
    .done (data, searchedArticlesNextTextStatus) ->
      throw "shouldn't have gotten here"
      start()
    .fail (jqXHR, searchedArticlesNextTextStatus, errorThrown) ->
      ok searchedArticlesNextTextStatus == 'abort'
      start()
    searchedArticles.abort()
  .fail (jqXHR, articlesNextTextStatus, errorThrown) ->
    start()

firehoseTest 'Add and Remove Agent', 2, (agent) ->

  .fail ->
    start()

firehoseTest 'Fetch (throws error because not enough info is set)', 1, (agent) ->
  company = agent.companies[0]
  company.fetch()
  .done ->
    kbCompany = Firehose.Company.companyWithKBCustomDomain company.knowledgeBaseCustomDomain
    throws kbCompany.fetch()
    start()
