Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests #64

Merged
merged 3 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Tests
on:
push:
branches: [ "main", release-*, develop ]
pull_request:
branches: [ "main", release-*, develop ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of commits
submodules: 'true'

- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

- name: Run FishyFlip.Tests
run: dotnet test src/FishyFlip.Tests/FishyFlip.Tests.csproj -- --report-trx --results-directory ../../dotnet-test-results

- name: Run WhiteWindLib.Tests
run: dotnet test src/WhiteWindLib.Tests/WhiteWindLib.Tests.csproj -- --report-trx --results-directory ../../dotnet-test-results

- name: Upload Test Results
uses: actions/upload-artifact@v4
with:
name: dotnet-test-results
path: dotnet-test-results
if: ${{ always() }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

dotnet-test-results/
whitewindlib.runsettings
fishyflip.runsettings
external/Drastic.FlipperKit/build/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@ namespace FishyFlip.Tests;
public class AuthorizedTests
{
static ATProtocol proto;
static string handle;
static string handle_2;
static string did;
static string did_2;
static string post_thread;
static string quote_post;
static string quote_post_2;
static string feed_generator;
static string follow_did;
static string block_did;
static string media_post;
static string images_post;
static string external_post;

public AuthorizedTests()
{
Expand All @@ -33,20 +20,7 @@ public AuthorizedTests()
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
feed_generator = "at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot";
follow_did = "did:plc:nrfz3bngz57p7g7yg6pbkyqr";
block_did = "did:plc:nrfz3bngz57p7g7yg6pbkyqr";
media_post = "at://did:plc:okblbaji7rz243bluudjlgxt/app.bsky.feed.post/3l46xtosyvf2y";
images_post = "at://did:plc:okblbaji7rz243bluudjlgxt/app.bsky.feed.post/3l46tcntvgy2a";
external_post = "at://did:plc:okblbaji7rz243bluudjlgxt/app.bsky.feed.post/3l46sr63j7r2m";
handle = (string?)context.Properties["BLUESKY_TEST_HANDLE"] ?? throw new ArgumentNullException();
handle_2 = "peepthisbot.bsky.social";

did = "did:plc:nrfz3bngz57p7g7yg6pbkyqr";
did_2 = "did:plc:okblbaji7rz243bluudjlgxt";
post_thread = "at://did:plc:okblbaji7rz243bluudjlgxt/app.bsky.feed.post/3l5bialwzz52f";
quote_post = "at://did:plc:okblbaji7rz243bluudjlgxt/app.bsky.feed.post/3knxmjdxlpl2r";
quote_post_2 = "at://did:plc:okblbaji7rz243bluudjlgxt/app.bsky.feed.post/3knxdo7r2cj2m";
string handle = (string?)context.Properties["BLUESKY_TEST_HANDLE"] ?? throw new ArgumentNullException();
string password = (string?)context.Properties["BLUESKY_TEST_PASSWORD"] ?? throw new ArgumentNullException();
string instance = "https://bsky.social";
var debugLog = new DebugLoggerProvider();
Expand All @@ -55,7 +29,7 @@ public static void ClassInitialize(TestContext context)
.WithInstanceUrl(new Uri(instance))
.WithLogger(debugLog.CreateLogger("FishyFlipTests"));
AuthorizedTests.proto = atProtocolBuilder.Build();
AuthorizedTests.proto.AuthenticateWithPasswordAsync(AuthorizedTests.handle, password).Wait();
AuthorizedTests.proto.AuthenticateWithPasswordAsync(handle, password).Wait();
}

[TestMethod]
Expand All @@ -74,9 +48,10 @@ public async Task GetPopularFeedGeneratorsAsync()
}

[TestMethod]
public async Task GetFeedAsyncTest()
[DataRow("at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot")]
public async Task GetFeedAsyncTest(string feedGenerator)
{
var atUri = ATUri.Create(AuthorizedTests.feed_generator);
var atUri = ATUri.Create(feedGenerator);
var result = await AuthorizedTests.proto.Feed.GetFeedAsync(atUri);
result.Switch(
success =>
Expand All @@ -90,9 +65,10 @@ public async Task GetFeedAsyncTest()
}

[TestMethod]
public async Task GetFeedGeneratorAsyncTest()
[DataRow("at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot")]
public async Task GetFeedGeneratorAsyncTest(string feedGenerator)
{
var atUri = ATUri.Create(AuthorizedTests.feed_generator);
var atUri = ATUri.Create(feedGenerator);
var result = await AuthorizedTests.proto.Feed.GetFeedGeneratorAsync(atUri);
result.Switch(
success =>
Expand All @@ -106,13 +82,14 @@ public async Task GetFeedGeneratorAsyncTest()
}

[TestMethod]
public async Task GetProfileAsyncTest()
[DataRow("drasticactions.xn--q9jyb4c")]
public async Task GetProfileAsyncTest(string handle1)
{
var result = await AuthorizedTests.proto.Actor.GetProfileAsync(ATHandle.Create(AuthorizedTests.handle) ?? throw new ArgumentNullException(nameof(AuthorizedTests.handle)));
var result = await AuthorizedTests.proto.Actor.GetProfileAsync(ATHandle.Create(handle1) ?? throw new ArgumentNullException(nameof(handle1)));
result.Switch(
success =>
{
Assert.AreEqual(success!.Handle, AuthorizedTests.handle);
Assert.AreEqual(success!.Handle, handle1);
},
failed =>
{
Expand All @@ -121,14 +98,15 @@ public async Task GetProfileAsyncTest()
}

[TestMethod]
public async Task GetProfilesAsyncWithHandlesTest()
[DataRow("drasticactions.xn--q9jyb4c", "peepthisbot.bsky.social")]
public async Task GetProfilesAsyncWithHandlesTest(string handle1, string handle2)
{
var result = await AuthorizedTests.proto.Actor.GetProfilesAsync(new[] { ATHandle.Create(AuthorizedTests.handle), ATHandle.Create(AuthorizedTests.handle_2) });
var result = await AuthorizedTests.proto.Actor.GetProfilesAsync(new[] { ATHandle.Create(handle1), ATHandle.Create(handle2) });
result.Switch(
success =>
{
Assert.AreEqual(AuthorizedTests.handle, success!.Profiles[0]!.Handle.ToString());
Assert.AreEqual(AuthorizedTests.handle_2.ToString(), success!.Profiles[1]!.Handle.ToString());
Assert.AreEqual(handle1, success!.Profiles[0]!.Handle.ToString());
Assert.AreEqual(handle2, success!.Profiles[1]!.Handle.ToString());
},
failed =>
{
Expand All @@ -137,10 +115,11 @@ public async Task GetProfilesAsyncWithHandlesTest()
}

[TestMethod]
public async Task GetProfilesAsyncWithDidTest()
[DataRow("did:plc:nrfz3bngz57p7g7yg6pbkyqr", "did:plc:okblbaji7rz243bluudjlgxt")]
public async Task GetProfilesAsyncWithDidTest(string did1, string did2)
{
var test1did = ATDid.Create(AuthorizedTests.did);
var test2did = ATDid.Create(AuthorizedTests.did_2);
var test1did = ATDid.Create(did1);
var test2did = ATDid.Create(did2);
var result = await AuthorizedTests.proto.Actor.GetProfilesAsync(new[] { test1did, test2did });
result.Switch(
success =>
Expand All @@ -155,10 +134,11 @@ public async Task GetProfilesAsyncWithDidTest()
}

[TestMethod]
public async Task GetPostsAsyncTest()
[DataRow("at://did:plc:okblbaji7rz243bluudjlgxt/app.bsky.feed.post/3knxmjdxlpl2r", "at://did:plc:okblbaji7rz243bluudjlgxt/app.bsky.feed.post/3knxdo7r2cj2m")]
public async Task GetPostsAsyncTest(string quotePost, string quotePost2)
{
var postUri = ATUri.Create(AuthorizedTests.quote_post);
var postUri2 = ATUri.Create(AuthorizedTests.quote_post_2);
var postUri = ATUri.Create(quotePost);
var postUri2 = ATUri.Create(quotePost2);
var postThreadResult = await AuthorizedTests.proto.Feed.GetPostsAsync(new[] { postUri, postUri2 });
postThreadResult.Switch(
success =>
Expand All @@ -173,31 +153,33 @@ public async Task GetPostsAsyncTest()
}

[TestMethod]
public async Task GetPostThreadAsyncTest()
[DataRow("at://did:plc:okblbaji7rz243bluudjlgxt/app.bsky.feed.post/3l5bialwzz52f")]
public async Task GetPostThreadAsyncTest(string postThread)
{
var postUri = ATUri.Create(AuthorizedTests.post_thread);
var postUri = ATUri.Create(postThread);
var postThreadResult = await AuthorizedTests.proto.Feed.GetPostThreadAsync(postUri);
postThreadResult.Switch(
success =>
{
Assert.AreEqual(postUri.ToString(), success!.Thread.Post!.Uri.ToString());
},
failed =>
{
Assert.Fail($"{failed.StatusCode}: {failed.Detail}");
});
{
Assert.Fail($"{failed.StatusCode}: {failed.Detail}");
});
}

[TestMethod]
public async Task GetQuotePostThreadAsyncTest()
[DataRow("", "")]
public async Task GetQuotePostThreadAsyncTest(string quotePost, string quotePost2)
{
var postUri = ATUri.Create(AuthorizedTests.quote_post);
var postUri = ATUri.Create(quotePost);
var postThreadResult = await AuthorizedTests.proto.Feed.GetPostThreadAsync(postUri);
postThreadResult.Switch(
success =>
{
Assert.AreEqual(postUri.ToString(), success!.Thread.Post!.Uri.ToString());
Assert.AreEqual(AuthorizedTests.quote_post_2, ((RecordViewEmbed)success!.Thread!.Post!.Embed!)!.Post.Uri.ToString());
Assert.AreEqual(quotePost2, ((RecordViewEmbed)success!.Thread!.Post!.Embed!)!.Post.Uri.ToString());
},
failed =>
{
Expand All @@ -206,9 +188,10 @@ public async Task GetQuotePostThreadAsyncTest()
}

[TestMethod]
public async Task GetExternalPostThreadAsyncTest()
[DataRow("")]
public async Task GetExternalPostThreadAsyncTest(string externalPost)
{
var postUri = ATUri.Create(AuthorizedTests.external_post);
var postUri = ATUri.Create(externalPost);
var postThreadResult = await AuthorizedTests.proto.Feed.GetPostThreadAsync(postUri);
postThreadResult.Switch(
success =>
Expand All @@ -222,9 +205,10 @@ public async Task GetExternalPostThreadAsyncTest()
}

[TestMethod]
public async Task GetImagesPostThreadAsyncTest()
[DataRow("at://did:plc:okblbaji7rz243bluudjlgxt/app.bsky.feed.post/3l46tcntvgy2a")]
public async Task GetImagesPostThreadAsyncTest(string imagesPost)
{
var postUri = ATUri.Create(AuthorizedTests.images_post);
var postUri = ATUri.Create(imagesPost);
var postThreadResult = await AuthorizedTests.proto.Feed.GetPostThreadAsync(postUri);
postThreadResult.Switch(
success =>
Expand All @@ -238,9 +222,10 @@ public async Task GetImagesPostThreadAsyncTest()
}

[TestMethod]
public async Task GetRecordWithMediaPostThreadAsyncTest()
[DataRow("at://did:plc:okblbaji7rz243bluudjlgxt/app.bsky.feed.post/3l46xtosyvf2y")]
public async Task GetRecordWithMediaPostThreadAsyncTest(string mediaPost)
{
var postUri = ATUri.Create(AuthorizedTests.media_post);
var postUri = ATUri.Create(mediaPost);
var postThreadResult = await AuthorizedTests.proto.Feed.GetPostThreadAsync(postUri);
postThreadResult.Switch(
success =>
Expand All @@ -254,9 +239,10 @@ public async Task GetRecordWithMediaPostThreadAsyncTest()
}

[TestMethod]
public async Task GetRepliesPostThreadAsyncTest()
[DataRow("")]
public async Task GetRepliesPostThreadAsyncTest(string postThread)
{
var postUri = ATUri.Create(AuthorizedTests.post_thread);
var postUri = ATUri.Create(postThread);
var postThreadResult = await AuthorizedTests.proto.Feed.GetPostThreadAsync(postUri);
postThreadResult.Switch(
success =>
Expand Down Expand Up @@ -361,7 +347,8 @@ public async Task CreatePostWithTagAsyncTest()
}

[TestMethod]
public async Task CreateAndRemoveListTest()
[DataRow("did:plc:nrfz3bngz57p7g7yg6pbkyqr")]
public async Task CreateAndRemoveListTest(string followDid)
{
var randomName = Guid.NewGuid().ToString();
var createList = (await AuthorizedTests.proto.Repo.CreateCurateListAsync(randomName, "Test List", DateTime.UtcNow)).HandleResult();
Expand All @@ -373,7 +360,7 @@ public async Task CreateAndRemoveListTest()
Assert.IsTrue(lists is not null);
Assert.IsTrue(lists!.Lists.Count() > 0);

var follow1 = ATDid.Create(AuthorizedTests.follow_did);
var follow1 = ATDid.Create(followDid);
var follow = (await AuthorizedTests.proto.Repo.CreateListItemAsync(follow1, createList.Uri)).HandleResult();
Assert.IsTrue(follow!.Cid is not null);
Assert.IsTrue(follow!.Uri is not null);
Expand Down Expand Up @@ -442,9 +429,10 @@ public async Task CreateAndRemoveLikeTest()
}

[TestMethod]
public async Task CreateAndRemoveFollowTest()
[DataRow("did:plc:nrfz3bngz57p7g7yg6pbkyqr")]
public async Task CreateAndRemoveFollowTest(string followDid)
{
var follow1 = ATDid.Create(AuthorizedTests.follow_did);
var follow1 = ATDid.Create(followDid);
var follow = (await AuthorizedTests.proto.Repo.CreateFollowAsync(follow1)).HandleResult();
Assert.IsTrue(follow!.Cid is not null);
Assert.IsTrue(follow!.Uri is not null);
Expand All @@ -454,9 +442,10 @@ public async Task CreateAndRemoveFollowTest()
}

[TestMethod]
public async Task CreateAndRemoveBlockTest()
[DataRow("did:plc:nrfz3bngz57p7g7yg6pbkyqr")]
public async Task CreateAndRemoveBlockTest(string blockDid)
{
var follow2 = ATDid.Create(AuthorizedTests.block_did);
var follow2 = ATDid.Create(blockDid);
var follow = (await AuthorizedTests.proto.Repo.CreateBlockAsync(follow2)).HandleResult();
Assert.IsTrue(follow!.Cid is not null);
Assert.IsTrue(follow!.Uri is not null);
Expand Down
24 changes: 24 additions & 0 deletions src/FishyFlip.Auth.Tests/FishyFlip.Auth.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="MSTest.Sdk/3.6.0">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<EnableMSTestRunner>true</EnableMSTestRunner>
</PropertyGroup>

<PropertyGroup>
<RunSettingsFilePath>$(MSBuildProjectDirectory)\fishyflip.runsettings</RunSettingsFilePath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FishyFlip\FishyFlip.csproj"/>
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions src/FishyFlip.Auth.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// <copyright file="GlobalUsings.cs" company="Drastic Actions">
// Copyright (c) Drastic Actions. All rights reserved.
// </copyright>

global using System.IdentityModel.Tokens.Jwt;
global using System.Net.Http.Headers;
global using System.Net.WebSockets;
global using System.Text;
global using System.Text.Encodings;
global using System.Text.Json;
global using System.Text.Json.Serialization;
global using System.Text.RegularExpressions;
global using System.Timers;
global using FishyFlip.Events;
global using FishyFlip.Models;
global using FishyFlip.Models.Internal;
global using FishyFlip.Tools;
global using FishyFlip.Tools.Cbor;
global using FishyFlip.Tools.Json;
global using Ipfs;
global using Microsoft.Extensions.Logging;
global using Microsoft.IdentityModel.Tokens;
global using Microsoft.Testing;
global using Microsoft.VisualStudio.TestTools.UnitTesting;
global using PeterO.Cbor;
3 changes: 3 additions & 0 deletions src/FishyFlip.Auth.Tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# FishyFlip.Tests

To run the tests, create a copy of `fishyflip.runsettings.sample` and rename it `fishyflip.runsettings`. Then, fill in the handle name and password fields.
10 changes: 10 additions & 0 deletions src/FishyFlip.Auth.Tests/Samples.cs

Large diffs are not rendered by default.

Loading