Skip to content

Commit

Permalink
fixed IsPublicApiEnabled and related test
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant Winney committed Feb 19, 2018
1 parent a921333 commit 072a91f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
11 changes: 9 additions & 2 deletions GhostSharp/GhostAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,20 @@ public bool IsPublicApiEnabled(string clientId = null, string clientSecret = nul

try
{
// todo: this /should/ work if suppressing exceptions - need test
return GetUsers(new UserQueryParams { Limit = 1, Fields = "id" }) != null;
return GetUsers(new UserQueryParams { Limit = 1, Fields = "id" }).Users != null;
}
catch (GhostSharpException)
{
if (SuppressionLevel == SuppressionLevel.None)
throw;
return false;
}
catch (Exception)
{
if (SuppressionLevel == SuppressionLevel.All)
return false;
throw;
}
}

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions GhostSharpTests/CreatePostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public CreatePostTests()
[Fact]
public void CreatePost_ReturnsPost_WhenPostCreated()
{
// todo: need to figure out why most fields aren't showing in post

createdPost = auth.CreatePost(GeneratePost());

Assert.Equal(title, createdPost.Title);
Expand Down
10 changes: 7 additions & 3 deletions GhostSharpTests/GET_AUTH_TOKEN.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using GhostSharp;
using GhostSharp.Entities;
using Xunit;

namespace GhostSharpTests
Expand All @@ -21,9 +22,12 @@ public void GetYourVeryOwnAuthToken()
[Fact]
public void IsPublicApiEnabled_ReturnsCorrectValue()
{
var auth = new GhostAPI(Url, ClientId, ClientSecret);

// Try disabling the API on your site and change this to Assert.False
var auth = new GhostAPI(Url, ClientId, ClientSecret)
{
SuppressionLevel = SuppressionLevel.GhostOnly
};

// Try disabling the API on your site and change this to Assert.False
Assert.True(auth.IsPublicApiEnabled());
}
}
Expand Down

0 comments on commit 072a91f

Please sign in to comment.