|
| 1 | +package tests |
| 2 | + |
| 3 | +import ( |
| 4 | + "strconv" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/MarvinJWendt/testza" |
| 8 | + |
| 9 | + "github.com/satisfactorymodding/smr-api/config" |
| 10 | + "github.com/satisfactorymodding/smr-api/db/postgres" |
| 11 | + "github.com/satisfactorymodding/smr-api/generated" |
| 12 | + "github.com/satisfactorymodding/smr-api/migrations" |
| 13 | +) |
| 14 | + |
| 15 | +func init() { |
| 16 | + migrations.SetMigrationDir("../migrations") |
| 17 | + config.SetConfigDir("../") |
| 18 | + postgres.EnableDebug() |
| 19 | +} |
| 20 | + |
| 21 | +func TestBootstrapVersions(t *testing.T) { |
| 22 | + ctx, client, stop := setup() |
| 23 | + defer stop() |
| 24 | + |
| 25 | + token, err := makeUser(ctx) |
| 26 | + testza.AssertNoError(t, err) |
| 27 | + |
| 28 | + // Run Twice to detect any cache issues |
| 29 | + for i := 0; i < 2; i++ { |
| 30 | + version := strconv.Itoa(i+1) + ".0.0" |
| 31 | + |
| 32 | + // Create |
| 33 | + createBootstrapVersion := authRequest(`mutation ($version: String!) { |
| 34 | + createBootstrapVersion(bootstrapVersion: { |
| 35 | + version: $version, |
| 36 | + satisfactory_version: 12345, |
| 37 | + stability: beta, |
| 38 | + link: "example.com", |
| 39 | + changelog: "Hello World", |
| 40 | + date: "2006-01-02T15:04:05Z" |
| 41 | + }) { |
| 42 | + id |
| 43 | + } |
| 44 | + }`, token) |
| 45 | + createBootstrapVersion.Var("version", version) |
| 46 | + |
| 47 | + var createBootstrapVersionResponse struct { |
| 48 | + CreateBootstrapVersion generated.BootstrapVersion |
| 49 | + } |
| 50 | + testza.AssertNoError(t, client.Run(ctx, createBootstrapVersion, &createBootstrapVersionResponse)) |
| 51 | + testza.AssertNotEqual(t, "", createBootstrapVersionResponse.CreateBootstrapVersion.ID) |
| 52 | + |
| 53 | + // Query One |
| 54 | + queryBootstrapVersion := authRequest(`query ($id: BootstrapVersionID!) { |
| 55 | + getBootstrapVersion(bootstrapVersionID: $id) { |
| 56 | + id |
| 57 | + version |
| 58 | + satisfactory_version |
| 59 | + stability |
| 60 | + link |
| 61 | + changelog |
| 62 | + date |
| 63 | + } |
| 64 | + }`, token) |
| 65 | + queryBootstrapVersion.Var("id", createBootstrapVersionResponse.CreateBootstrapVersion.ID) |
| 66 | + |
| 67 | + var queryBootstrapVersionResponse struct { |
| 68 | + GetBootstrapVersion generated.BootstrapVersion |
| 69 | + } |
| 70 | + testza.AssertNoError(t, client.Run(ctx, queryBootstrapVersion, &queryBootstrapVersionResponse)) |
| 71 | + testza.AssertEqual(t, createBootstrapVersionResponse.CreateBootstrapVersion.ID, queryBootstrapVersionResponse.GetBootstrapVersion.ID) |
| 72 | + testza.AssertEqual(t, version, queryBootstrapVersionResponse.GetBootstrapVersion.Version) |
| 73 | + testza.AssertEqual(t, 12345, queryBootstrapVersionResponse.GetBootstrapVersion.SatisfactoryVersion) |
| 74 | + testza.AssertEqual(t, generated.VersionStabilitiesBeta, queryBootstrapVersionResponse.GetBootstrapVersion.Stability) |
| 75 | + testza.AssertEqual(t, "example.com", queryBootstrapVersionResponse.GetBootstrapVersion.Link) |
| 76 | + testza.AssertEqual(t, "Hello World", queryBootstrapVersionResponse.GetBootstrapVersion.Changelog) |
| 77 | + |
| 78 | + // Update |
| 79 | + updateBootstrapVersion := authRequest(`mutation ($id: BootstrapVersionID!) { |
| 80 | + updateBootstrapVersion( |
| 81 | + bootstrapVersionId: $id, |
| 82 | + bootstrapVersion: { |
| 83 | + changelog: "Foo Bar", |
| 84 | + } |
| 85 | + ) { |
| 86 | + id |
| 87 | + } |
| 88 | + }`, token) |
| 89 | + updateBootstrapVersion.Var("id", createBootstrapVersionResponse.CreateBootstrapVersion.ID) |
| 90 | + |
| 91 | + var updateBootstrapVersionResponse struct { |
| 92 | + UpdateBootstrapVersion generated.BootstrapVersion |
| 93 | + } |
| 94 | + testza.AssertNoError(t, client.Run(ctx, updateBootstrapVersion, &updateBootstrapVersionResponse)) |
| 95 | + |
| 96 | + // Query Many |
| 97 | + queryBootstrapVersions := authRequest(`query { |
| 98 | + getBootstrapVersions { |
| 99 | + count |
| 100 | + bootstrap_versions { |
| 101 | + id |
| 102 | + version |
| 103 | + satisfactory_version |
| 104 | + stability |
| 105 | + link |
| 106 | + changelog |
| 107 | + date |
| 108 | + } |
| 109 | + } |
| 110 | + }`, token) |
| 111 | + |
| 112 | + var queryBootstrapVersionsResponse struct { |
| 113 | + GetBootstrapVersions generated.GetBootstrapVersions |
| 114 | + } |
| 115 | + testza.AssertNoError(t, client.Run(ctx, queryBootstrapVersions, &queryBootstrapVersionsResponse)) |
| 116 | + testza.AssertEqual(t, 1, queryBootstrapVersionsResponse.GetBootstrapVersions.Count) |
| 117 | + testza.AssertEqual(t, 1, len(queryBootstrapVersionsResponse.GetBootstrapVersions.BootstrapVersions)) |
| 118 | + testza.AssertEqual(t, createBootstrapVersionResponse.CreateBootstrapVersion.ID, queryBootstrapVersionsResponse.GetBootstrapVersions.BootstrapVersions[0].ID) |
| 119 | + testza.AssertEqual(t, version, queryBootstrapVersionsResponse.GetBootstrapVersions.BootstrapVersions[0].Version) |
| 120 | + testza.AssertEqual(t, 12345, queryBootstrapVersionsResponse.GetBootstrapVersions.BootstrapVersions[0].SatisfactoryVersion) |
| 121 | + testza.AssertEqual(t, generated.VersionStabilitiesBeta, queryBootstrapVersionsResponse.GetBootstrapVersions.BootstrapVersions[0].Stability) |
| 122 | + testza.AssertEqual(t, "example.com", queryBootstrapVersionsResponse.GetBootstrapVersions.BootstrapVersions[0].Link) |
| 123 | + testza.AssertEqual(t, "Foo Bar", queryBootstrapVersionsResponse.GetBootstrapVersions.BootstrapVersions[0].Changelog) |
| 124 | + |
| 125 | + // Delete |
| 126 | + deleteBootstrapVersion := authRequest(`mutation ($id: BootstrapVersionID!) { |
| 127 | + deleteBootstrapVersion(bootstrapVersionId: $id) |
| 128 | + }`, token) |
| 129 | + deleteBootstrapVersion.Var("id", createBootstrapVersionResponse.CreateBootstrapVersion.ID) |
| 130 | + |
| 131 | + var deleteBootstrapVersionResponse struct { |
| 132 | + DeleteBootstrapVersion bool |
| 133 | + } |
| 134 | + testza.AssertNoError(t, client.Run(ctx, deleteBootstrapVersion, &deleteBootstrapVersionResponse)) |
| 135 | + testza.AssertTrue(t, deleteBootstrapVersionResponse.DeleteBootstrapVersion) |
| 136 | + } |
| 137 | +} |
0 commit comments