Skip to content

Commit

Permalink
make loaders and game versions required in version file endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Zechiax committed Aug 6, 2023
1 parent c835ee3 commit 40df6d2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ Task DeleteVersionByHashAsync(string hash,
/// <param name="loaders"> The loaders to filter by </param>
/// <param name="gameVersions"> The game versions to filter by </param>
/// <returns> The latest version of a project, that matches the filters </returns>
Task<Models.Version> GetLatestVersionByHashAsync(string hash, HashAlgorithm hashAlgorithm = HashAlgorithm.Sha1,
string[]? loaders = null, string[]? gameVersions = null);
Task<Models.Version> GetLatestVersionByHashAsync(string hash, HashAlgorithm hashAlgorithm,
string[] loaders, string[] gameVersions);

/// <summary>
/// Gets the latest version of multiple projects by a file hash
Expand All @@ -56,6 +56,6 @@ Task DeleteVersionByHashAsync(string hash,
/// <param name="gameVersions"> The game versions to filter by </param>
/// <returns> A dictionary of hashes and their respective latest versions that match the filters </returns>
Task<IDictionary<string, Models.Version>> GetMultipleLatestVersionsByHashAsync(string[] hashes,
HashAlgorithm hashAlgorithm = HashAlgorithm.Sha1,
string[]? loaders = null, string[]? gameVersions = null);
HashAlgorithm hashAlgorithm,
string[] loaders, string[] gameVersions);
}
14 changes: 4 additions & 10 deletions src/Modrinth.Net/Endpoints/VersionFile/VersionFileEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,9 @@ public async Task DeleteVersionByHashAsync(string hash, HashAlgorithm hashAlgori

/// <inheritdoc />
public async Task<Models.Version> GetLatestVersionByHashAsync(string hash,
HashAlgorithm hashAlgorithm = HashAlgorithm.Sha1,
string[]? loaders = null, string[]? gameVersions = null)
HashAlgorithm hashAlgorithm,
string[] loaders, string[] gameVersions)
{
loaders = loaders ?? Array.Empty<string>();
gameVersions = gameVersions ?? Array.Empty<string>();

var reqMsg = new HttpRequestMessage();
reqMsg.Method = HttpMethod.Post;
reqMsg.RequestUri = new Uri(VersionFilePathSegment + '/' + hash + "/update", UriKind.Relative);
Expand All @@ -103,12 +100,9 @@ public async Task DeleteVersionByHashAsync(string hash, HashAlgorithm hashAlgori

/// <inheritdoc />
public async Task<IDictionary<string, Models.Version>> GetMultipleLatestVersionsByHashAsync(string[] hashes,
HashAlgorithm hashAlgorithm = HashAlgorithm.Sha1,
string[]? loaders = null, string[]? gameVersions = null)
HashAlgorithm hashAlgorithm,
string[] loaders, string[] gameVersions)
{
loaders = loaders ?? Array.Empty<string>();
gameVersions = gameVersions ?? Array.Empty<string>();

var reqMsg = new HttpRequestMessage();
reqMsg.Method = HttpMethod.Post;
reqMsg.RequestUri = new Uri("version_files/update", UriKind.Relative);
Expand Down
6 changes: 3 additions & 3 deletions test/Modrinth.Net.Test/ModrinthApiTests/EndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class EndpointTests

protected static readonly string[] ValidSha512Hashes =
{
"f62b94dbdb7ec79c1cc9f7f01a07b72828e77d22426552cd876d0fa8ba2a446efaecaea262ed481b2f77fa57063a3bdcd1c5febb8ae97a766d82abf3eb9ee198",
"88014dd2d5fe7a259648eb716690f282e220556665ff20746bfa1f1d5a5f480e92fa94e07ea64db700c66720977d0c2147954efbf2c0c48bf38e419f04820453"
"bace1768e893e60574dcb1155e057a2fd0da3f3400c862a93c37dfe4d7908de1739b3b72190353f1a2a981ec18e1175d1dcf2109f0fb64ffdc73c45629a4cf55",
"3651e6cdb1dbb46580f27386caa01c88d28e51a5feec57cc435be73be25d718da9a719798e2b887e0fde14b6eaa970f30ee7220ff1f81489acd6174840c34d06"
};

protected static readonly string[] ValidSha1Hashes =
{"7e64ba677dbae046389b63a4db324284355987db", "fde0d8156d8d46b2b0f9d09906ef7f83ce712517"};
{"8b0a4139d9e82300b7aac82f2402ec3497991c52", "429eb439f0835e31fbbfd00234ef2daa8ecc8a87"};

private static readonly IConfigurationRoot Configuration =
new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
Expand Down
92 changes: 0 additions & 92 deletions test/Modrinth.Net.Test/ModrinthApiTests/VersionFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,56 +66,6 @@ public async Task GetMultipleVersionsFromHashesSha512()
}

[Test]
[TestCase(0)]
[TestCase(1)]
public async Task GetLatestVersionFromHashSha1(int index)
{
var hash = ValidSha1Hashes[index];

var version = await Client.VersionFile.GetLatestVersionByHashAsync(hash);

Assert.That(version, Is.Not.Null);

var versions = await Client.Version.GetProjectVersionListAsync(version.ProjectId);

Assert.Multiple(() =>
{
Assert.That(versions, Is.Not.Null);
Assert.That(versions, Is.Not.Empty);
// We check that the version is the latest version
Assert.That(version.Id, Is.EqualTo(versions[0].Id));
});
}

[Test]
[TestCase(0)]
[TestCase(1)]
public async Task GetLatestVersionFromHashSha512(int index)
{
var hash = ValidSha512Hashes[index];

var version = await Client.VersionFile.GetLatestVersionByHashAsync(hash, HashAlgorithm.Sha512);

Assert.That(version, Is.Not.Null);

var versions = await Client.Version.GetProjectVersionListAsync(version.ProjectId);

Assert.Multiple(() =>
{
Assert.That(versions, Is.Not.Null);
Assert.That(versions, Is.Not.Empty);
// We check that the version is the latest version
Assert.That(version.Id, Is.EqualTo(versions[0].Id));
});
}

[Test]
[TestCase(0, new string[] { }, new string[] { })]
[TestCase(0, new[] {"forge"}, new string[] { })]
[TestCase(0, new string[] { }, new[] {"1.18.1"})]
[TestCase(0, new[] {"quilt"}, new[] {"1.19"})]
[TestCase(0, new[] {"fabric"}, new[] {"1.17.1"})]
public async Task GetLatestVersionFromHashSha1WithFilters(int index, string[] loaders, string[] gameVersions)
{
Expand All @@ -133,10 +83,6 @@ public async Task GetLatestVersionFromHashSha1WithFilters(int index, string[] lo
}

[Test]
[TestCase(0, new string[] { }, new string[] { })]
[TestCase(0, new[] {"forge"}, new string[] { })]
[TestCase(0, new string[] { }, new[] {"1.18.1"})]
[TestCase(0, new[] {"quilt"}, new[] {"1.19"})]
[TestCase(0, new[] {"fabric"}, new[] {"1.17.1"})]
public async Task GetLatestVersionFromHashSha512WithFilters(int index, string[] loaders, string[] gameVersions)
{
Expand All @@ -154,40 +100,6 @@ public async Task GetLatestVersionFromHashSha512WithFilters(int index, string[]
}

[Test]
public async Task GetMultipleLatestVersionsFromHashSha1()
{
var hashes = ValidSha1Hashes;

var versions = await Client.VersionFile.GetMultipleLatestVersionsByHashAsync(hashes);

// We currently don't check if the versions are the latest versions
Assert.Multiple(() =>
{
Assert.That(versions, Is.Not.Null);
Assert.That(versions, Is.Not.Empty);
});
}

[Test]
public async Task GetMultipleLatestVersionsFromHashSha512()
{
var hashes = ValidSha512Hashes;

var versions = await Client.VersionFile.GetMultipleLatestVersionsByHashAsync(hashes, HashAlgorithm.Sha512);

// We currently don't check if the versions are the latest versions
Assert.Multiple(() =>
{
Assert.That(versions, Is.Not.Null);
Assert.That(versions, Is.Not.Empty);
});
}

[Test]
[TestCase(0, new string[] { }, new string[] { })]
[TestCase(0, new[] {"forge"}, new string[] { })]
[TestCase(0, new string[] { }, new[] {"1.18.1"})]
[TestCase(0, new[] {"quilt"}, new[] {"1.19"})]
[TestCase(0, new[] {"fabric"}, new[] {"1.17.1"})]
public async Task GetMultipleLatestVersionsFromHashSha1WithFilters(int index, string[] loaders,
string[] gameVersions)
Expand All @@ -212,10 +124,6 @@ await Client.VersionFile.GetMultipleLatestVersionsByHashAsync(hashes, HashAlgori
}

[Test]
[TestCase(0, new string[] { }, new string[] { })]
[TestCase(0, new[] {"forge"}, new string[] { })]
[TestCase(0, new string[] { }, new[] {"1.18.1"})]
[TestCase(0, new[] {"quilt"}, new[] {"1.19"})]
[TestCase(0, new[] {"fabric"}, new[] {"1.17.1"})]
public async Task GetMultipleLatestVersionsFromHashSha512WithFilters(int index, string[] loaders,
string[] gameVersions)
Expand Down

0 comments on commit 40df6d2

Please sign in to comment.