-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
196 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/MarvinJWendt/testza" | ||
"github.com/satisfactorymodding/smr-api/generated" | ||
) | ||
|
||
const getQuery = `query GetMods($offset: Int!, $limit: Int!, $search: String, $order: Order, $orderBy: ModFields, $tagIDs: [TagID!]) { | ||
getMods( | ||
filter: {limit: $limit, offset: $offset, search: $search, order: $order, order_by: $orderBy, tagIDs: $tagIDs} | ||
) { | ||
count | ||
mods { | ||
mod_reference | ||
tags { | ||
id | ||
} | ||
} | ||
} | ||
}` | ||
|
||
func TestGetModLimitOffset(t *testing.T) { | ||
ctx, client, stop := setup() | ||
defer stop() | ||
|
||
token, _, err := makeUser(ctx) | ||
testza.AssertNoError(t, err) | ||
|
||
tags := seedTags(t, ctx, token, client) | ||
seedMods(t, ctx, token, client, tags[0]) | ||
|
||
getRequest := authRequest(getQuery, token) | ||
|
||
getRequest.Var("offset", "4") | ||
getRequest.Var("limit", "2") | ||
getRequest.Var("order", "asc") | ||
getRequest.Var("orderBy", "created_at") | ||
|
||
var getResponse struct { | ||
GetMods generated.GetMods | ||
} | ||
testza.AssertNoError(t, client.Run(ctx, getRequest, &getResponse)) | ||
testza.AssertEqual(t, 10, getResponse.GetMods.Count) | ||
testza.AssertEqual(t, 2, len(getResponse.GetMods.Mods)) | ||
testza.AssertEqual(t, "resource_overhaul", getResponse.GetMods.Mods[0].ModReference) | ||
testza.AssertEqual(t, "automated_defense", getResponse.GetMods.Mods[1].ModReference) | ||
testza.AssertEqual(t, 0, len(getResponse.GetMods.Mods[0].Tags)) | ||
testza.AssertEqual(t, 1, len(getResponse.GetMods.Mods[1].Tags)) | ||
testza.AssertEqual(t, tags[0], getResponse.GetMods.Mods[1].Tags[0].ID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/MarvinJWendt/testza" | ||
"github.com/machinebox/graphql" | ||
"github.com/satisfactorymodding/smr-api/generated" | ||
"github.com/satisfactorymodding/smr-api/util" | ||
) | ||
|
||
func seedTags(t *testing.T, ctx context.Context, token string, client *graphql.Client) []string { | ||
tags := []string{ | ||
"hello", | ||
"foo", | ||
} | ||
|
||
ids := make([]string, len(tags)) | ||
for i, tag := range tags { | ||
createRequest := authRequest(`mutation CreateTag($name: TagName!) { | ||
createTag(tagName: $name, description: "N/A") { | ||
id | ||
} | ||
}`, token) | ||
createRequest.Var("name", tag) | ||
|
||
var createResponse struct { | ||
CreateTag generated.Tag | ||
} | ||
testza.AssertNoError(t, client.Run(ctx, createRequest, &createResponse)) | ||
testza.AssertNotEqual(t, "", createResponse.CreateTag.ID) | ||
|
||
ids[i] = createResponse.CreateTag.ID | ||
} | ||
|
||
return ids | ||
} | ||
|
||
type testMod struct { | ||
Name string `json:"name"` | ||
ShortDescription string `json:"short_description"` | ||
FullDescription string `json:"full_description"` | ||
ModReference string `json:"mod_reference"` | ||
TagIDs []string `json:"tagIDs"` | ||
} | ||
|
||
func seedMods(t *testing.T, ctx context.Context, token string, client *graphql.Client, tagID string) []string { | ||
mods := []testMod{ | ||
{ | ||
Name: "Advanced Robotics", | ||
ShortDescription: "Enhances robot efficiency and adds new automation features.", | ||
ModReference: "advanced_robotics", | ||
}, | ||
{ | ||
Name: "Eco-Friendly Power", | ||
ShortDescription: "Introduces sustainable energy sources and eco-friendly power management.", | ||
ModReference: "eco_friendly_power", | ||
}, | ||
{ | ||
Name: "Quantum Transport", | ||
ShortDescription: "Allows instantaneous item transport using quantum entanglement.", | ||
ModReference: "quantum_transport", | ||
}, | ||
{ | ||
Name: "Mega Factory", | ||
ShortDescription: "Expands factory building limits and adds new large-scale production tools.", | ||
ModReference: "mega_factory", | ||
}, | ||
{ | ||
Name: "Resource Overhaul", | ||
ShortDescription: "Revamps resource extraction and processing for more efficiency.", | ||
ModReference: "resource_overhaul", | ||
}, | ||
{ | ||
Name: "Automated Defense", | ||
ShortDescription: "Adds advanced automated defense systems to protect your factory.", | ||
ModReference: "automated_defense", | ||
TagIDs: []string{tagID}, | ||
}, | ||
{ | ||
Name: "AI Assistant", | ||
ShortDescription: "Introduces an AI assistant to help manage and optimize your factory.", | ||
ModReference: "ai_assistant", | ||
TagIDs: []string{tagID}, | ||
}, | ||
{ | ||
Name: "Fusion Reactors", | ||
ShortDescription: "Adds fusion reactors as a high-efficiency power source.", | ||
ModReference: "fusion_reactors", | ||
TagIDs: []string{tagID}, | ||
}, | ||
{ | ||
Name: "Modular Production", | ||
ShortDescription: "Allows modular production units for flexible factory layouts.", | ||
ModReference: "modular_production", | ||
TagIDs: []string{tagID}, | ||
}, | ||
{ | ||
Name: "Nanotech Manufacturing", | ||
ShortDescription: "Incorporates nanotechnology for ultra-precise manufacturing processes.", | ||
ModReference: "nanotech_manufacturing", | ||
TagIDs: []string{tagID}, | ||
}, | ||
} | ||
|
||
util.ModsPer24h = len(mods) | ||
|
||
ids := make([]string, len(mods)) | ||
for i, mod := range mods { | ||
mod.FullDescription = "N/A" | ||
|
||
createRequest := authRequest(`mutation CreateMod($mod: NewMod!) { | ||
createMod(mod: $mod) { | ||
id | ||
} | ||
}`, token) | ||
createRequest.Var("mod", mod) | ||
|
||
var createResponse struct { | ||
CreateMod generated.Mod | ||
} | ||
testza.AssertNoError(t, client.Run(ctx, createRequest, &createResponse)) | ||
testza.AssertNotEqual(t, "", createResponse.CreateMod.ID) | ||
|
||
ids[i] = createResponse.CreateMod.ID | ||
} | ||
|
||
return ids | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package util | ||
|
||
var ModsPer24h = 4 |