Skip to content
Draft
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
32 changes: 28 additions & 4 deletions tests/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,34 @@ func TestSameVersion(t *testing.T) {
ctx, client, stop := setup()
defer stop()

modID := RunVersionTest(ctx, t, client, "testdata/DuplicateMod.smod", false, "DuplicateMod", "", "")
modID, _ := RunVersionTest(ctx, t, client, "testdata/DuplicateMod.smod", false, "DuplicateMod", "", "")
RunVersionTest(ctx, t, client, "testdata/DuplicateMod.smod", false, "DuplicateMod", modID, "this mod already has a version with this name")
}

func TestSameSemver(t *testing.T) {
ctx, client, stop := setup()
defer stop()

modID, versionID := RunVersionTest(ctx, t, client, "testdata/DuplicateMod.smod", false, "DuplicateMod", "", "")
//NEED TO SOMEHOW DELETE THE MOD

token, _, err := makeUser(ctx)
testza.AssertNoError(t, err)

deleteRequest := authRequest(`mutation DeleteVersion($versionId: VersionID!) {
deleteVersion(versionId: $versionId)
}`, token)
deleteRequest.Var("versionId", versionID)

var deleteResponse struct {
DeleteVersion bool
}
testza.AssertNoError(t, client.Run(ctx, deleteRequest, &deleteResponse))
testza.AssertTrue(t, deleteResponse.DeleteVersion)

RunVersionTest(ctx, t, client, "testdata/DuplicateMod.smod", false, "DuplicateMod", modID, "this mod already has a version with this semver")
}

func TestModWithMissingDependency(t *testing.T) {
RunVersionTestWrapper(t, "testdata/ModWithMissingDependency.smod", false, "ModWithMissingDependency", "ent: mod not found")
}
Expand All @@ -75,11 +99,11 @@ func RunVersionTestWrapper(t *testing.T, modFilePath string, executeVirusCheck b
RunVersionTest(ctx, t, client, modFilePath, executeVirusCheck, modReference, "", expectError)
}

func RunVersionTest(ctx context.Context, t *testing.T, client *graphql.Client, modFilePath string, executeVirusCheck bool, modReference string, reuseModID string, expectError string) string {
func RunVersionTest(ctx context.Context, t *testing.T, client *graphql.Client, modFilePath string, executeVirusCheck bool, modReference string, reuseModID string, expectError string) (string, string) {
if executeVirusCheck && (!viper.IsSet("virustotal.key") || viper.GetString("virustotal.key") == "") {
println("missing virustotal key from config, skipping")
t.SkipNow()
return ""
return "", ""
}

viper.Set("skip-virus-check", !executeVirusCheck)
Expand Down Expand Up @@ -394,5 +418,5 @@ func RunVersionTest(ctx context.Context, t *testing.T, client *graphql.Client, m
})
}

return modID
return modID, versionID
}
24 changes: 24 additions & 0 deletions workflows/versionupload/extract_mod_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"go.temporal.io/sdk/temporal"

"github.com/satisfactorymodding/smr-api/db"
"github.com/satisfactorymodding/smr-api/db/schema"
version2 "github.com/satisfactorymodding/smr-api/generated/ent/version"
"github.com/satisfactorymodding/smr-api/util"
"github.com/satisfactorymodding/smr-api/validation"
Expand Down Expand Up @@ -62,6 +63,29 @@ func (*A) ExtractModInfoActivity(ctx context.Context, args ExtractModInfoArgs) (
return nil, temporal.NewNonRetryableApplicationError("this mod already has a version with this name", "fatal", nil)
}

if modInfo.Semver != nil {
major := int(modInfo.Semver.Major())
minor := int(modInfo.Semver.Minor())
patch := int(modInfo.Semver.Patch())

semverCount, err := db.From(schema.SkipSoftDelete(ctx)).Version.Query().
Where(
version2.ModID(mod.ID),
version2.VersionMajor(major),
version2.VersionMinor(minor),
version2.VersionPatch(patch),
version2.DeletedAtNotNil(),
).
Count(ctx)
if err != nil {
return nil, temporal.NewNonRetryableApplicationError("database error", "fatal", err)
}

if semverCount > 0 {
return nil, temporal.NewNonRetryableApplicationError("this mod already has a version with this semver", "fatal", nil)
}
}

// Allow only new 5 versions per 24h
versions, err := db.From(ctx).Version.Query().
Order(version2.ByCreatedAt(sql.OrderAsc())).
Expand Down
Loading