Skip to content

Commit 3812f0f

Browse files
authored
added Tests, minor cleanup (#5)
* removed deprecated functions * moved SearchResult * first pass using Swift Testing
1 parent 6da6ab0 commit 3812f0f

17 files changed

+478
-20
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1610"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES"
8+
buildArchitectures = "Automatic">
9+
<BuildActionEntries>
10+
<BuildActionEntry
11+
buildForTesting = "YES"
12+
buildForRunning = "YES"
13+
buildForProfiling = "YES"
14+
buildForArchiving = "YES"
15+
buildForAnalyzing = "YES">
16+
<BuildableReference
17+
BuildableIdentifier = "primary"
18+
BlueprintIdentifier = "xivapi-swift"
19+
BuildableName = "xivapi-swift"
20+
BlueprintName = "xivapi-swift"
21+
ReferencedContainer = "container:">
22+
</BuildableReference>
23+
</BuildActionEntry>
24+
</BuildActionEntries>
25+
</BuildAction>
26+
<TestAction
27+
buildConfiguration = "Debug"
28+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
29+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
30+
shouldUseLaunchSchemeArgsEnv = "YES"
31+
shouldAutocreateTestPlan = "YES">
32+
<Testables>
33+
<TestableReference
34+
skipped = "NO">
35+
<BuildableReference
36+
BuildableIdentifier = "primary"
37+
BlueprintIdentifier = "xivapi-swiftTests"
38+
BuildableName = "xivapi-swiftTests"
39+
BlueprintName = "xivapi-swiftTests"
40+
ReferencedContainer = "container:">
41+
</BuildableReference>
42+
</TestableReference>
43+
</Testables>
44+
</TestAction>
45+
<LaunchAction
46+
buildConfiguration = "Debug"
47+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
48+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
49+
launchStyle = "0"
50+
useCustomWorkingDirectory = "NO"
51+
ignoresPersistentStateOnLaunch = "NO"
52+
debugDocumentVersioning = "YES"
53+
debugServiceExtension = "internal"
54+
allowLocationSimulation = "YES">
55+
</LaunchAction>
56+
<ProfileAction
57+
buildConfiguration = "Release"
58+
shouldUseLaunchSchemeArgsEnv = "YES"
59+
savedToolIdentifier = ""
60+
useCustomWorkingDirectory = "NO"
61+
debugDocumentVersioning = "YES">
62+
<MacroExpansion>
63+
<BuildableReference
64+
BuildableIdentifier = "primary"
65+
BlueprintIdentifier = "xivapi-swift"
66+
BuildableName = "xivapi-swift"
67+
BlueprintName = "xivapi-swift"
68+
ReferencedContainer = "container:">
69+
</BuildableReference>
70+
</MacroExpansion>
71+
</ProfileAction>
72+
<AnalyzeAction
73+
buildConfiguration = "Debug">
74+
</AnalyzeAction>
75+
<ArchiveAction
76+
buildConfiguration = "Release"
77+
revealArchiveInOrganizer = "YES">
78+
</ArchiveAction>
79+
</Scheme>

Package.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ let package = Package(
1515
resources: [
1616
.process("Resources")
1717
]
18+
),
19+
.testTarget(
20+
name: "xivapi-swiftTests",
21+
dependencies: ["xivapi-swift"]
1822
)
1923
]
2024
)

Sources/xivapi-swift/Sheets/Icon.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ public struct Icon: Codable, Hashable {
77
}
88

99
public extension Icon {
10-
@available(*, deprecated, message: "Use iconUrl(format:) instead.", renamed: "iconUrl()" )
11-
var iconUrl: URL? { path != nil ? Endpoint.asset(at: path!, format: .jpg) : nil }
12-
@available(*, deprecated, message: "Use iconUrlHD(format:) instead.", renamed: "iconUrlHD()" )
13-
var iconUrlHD: URL? { path_hr1 != nil ? Endpoint.asset(at: path_hr1!, format: .jpg) : nil }
1410

1511
func iconUrl(format: Format = .jpg) -> URL? {
1612
guard let path else { return nil }

Sources/xivapi-swift/Sheets/Map.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ public struct XivMap: Codable {
77
public extension XivMap {
88
var name: String { fields.PlaceName.fields.Name }
99
var region: String { fields.PlaceNameRegion.fields.Name }
10-
@available(*, deprecated, message: "Use mapUrl(format:) instead.", renamed: "mapUrl()" )
11-
var mapUrl: URL? {
12-
let territoryId = fields.Id
13-
let path = "ui/map/\(territoryId)/\(territoryId.replacingOccurrences(of: "/", with: ""))_m.tex"
14-
return Endpoint.asset(at: path, format: .jpg)
15-
}
1610

1711
func mapUrl(format: Format = .jpg) -> URL? {
1812
let territoryId = fields.Id

Sources/xivapi-swift/Sheets/TripleTriadCard.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ public struct TripleTriadCardFields: Codable {
1313
public extension TripleTriadCard {
1414

1515
var backgroundUrl: URL? { Endpoint.asset(at: "ui/uld/CardTripleTriad_hr1.tex") }
16-
@available(*, deprecated, message: "Use imageUrl(format:) instead.", renamed: "imageUrl()" )
17-
var imageUrl: URL? {
18-
19-
let cardNumber = row_id.description
20-
let paddedString = String(repeating: "0", count: 3 - cardNumber.count).appending(cardNumber)
21-
let path = "ui/icon/087000/087\(paddedString)_hr1.tex"
22-
let url = Endpoint.asset(at: path, format: .png)
23-
24-
return url
25-
}
2616

2717
func imageUrl(format: Format = .png) -> URL? {
2818

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Testing
2+
import xivapi_swift
3+
4+
@Suite("Action")
5+
struct Action_Tests {
6+
let xivapi = xivapiClient()
7+
8+
@Test("Blue Mage") func AozAction() async throws {
9+
let action = try #require(await xivapi.getSheet(.AozAction, id: 104) as AozAction?)
10+
11+
#expect(action.name == "Nightbloom")
12+
#expect(action.number == 104)
13+
#expect(action.category.name == "Ability")
14+
#expect(action.actionIcon.id == 3357)
15+
#expect(action.transientIcon.id == 72305)
16+
#expect(action.description == "This extravagant technique belongs to Tsukuyomi, Lady of the Moon, whose malignant ire manifests as a field of flowers which then burst apart in a hail of deadly petals. Accept the inevitability of the grave, and the power of the nightbloom is yours to wield...")
17+
}
18+
19+
@Test("PvE: TBN") func Action() async throws {
20+
let action = try #require(await xivapi.getAction(7393))
21+
22+
#expect(action.name == "The Blackest Night")
23+
}
24+
25+
@Test("PvP: TBN") func PvPAction() async throws {
26+
let action = try #require(await xivapi.getAction(29093))
27+
28+
#expect(action.name == "the Blackest Night")
29+
}
30+
31+
@Test("PvP: Glory Slash") func PvPAction2() async throws {
32+
let action = try #require(await xivapi.getPvPAction(2))
33+
34+
#expect(action.action.name == "Glory Slash")
35+
}
36+
37+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import Testing
2+
import Foundation
3+
import xivapi_swift
4+
5+
@Suite("Client")
6+
struct Client_Tests {
7+
let xivapi = xivapiClient()
8+
9+
//MARK: commonly used
10+
@Test("Search: Name (Recipe/Item)") func TestSearch() async throws {
11+
let searchResults = try #require(await xivapi.search([.Recipe, .Item], name: "Grade 2"))
12+
#expect(searchResults.results.count > 0)
13+
#expect(searchResults.results.first?.icon != nil)
14+
#expect(searchResults.results.first?.name != nil)
15+
}
16+
17+
@Test("Search: iLvl (Recipe/Item)") func TestSearch2() async throws {
18+
let searchResults = try #require(await xivapi.search([.Recipe, .Item], customQueries: [URLQueryItem(name: "query", value: "LevelItem>=600")]))
19+
#expect(searchResults.results.count > 0)
20+
#expect(searchResults.results.first?.icon != nil)
21+
#expect(searchResults.results.first?.name != nil)
22+
}
23+
24+
@Test("URLs") func TestURLs() async throws {
25+
let searchUrl1 = xivapi.searchUrl([.Item, .Recipe], name: "Grade 2", next: nil)
26+
let searchUrl2 = xivapi.searchUrl([.Recipe], customQueries: [URLQueryItem(name: "query", value: "ItemResult=39727")], next: nil)
27+
let searchUrl3 = xivapi.searchUrl([.Item, .Recipe], customQueries: [URLQueryItem(name: "query", value: "LevelItem>=600")], next: nil)
28+
29+
let assetUrl = xivapi.assetUrl(at: "ui/icon/030000/030639_hr1.tex", format: .png)
30+
31+
#expect(searchUrl1 != nil)
32+
#expect(searchUrl2 != nil)
33+
#expect(searchUrl3 != nil)
34+
#expect(assetUrl != nil)
35+
}
36+
37+
@Test("Decode Item") func DecodeItem() async throws {
38+
let item = try #require(await xivapi.getItem(44162))
39+
#expect(item.name == "Grade 2 Gemdraught of Strength")
40+
}
41+
42+
@Test("Decode ItemMinimal") func DecodeItemMinimal() async throws {
43+
let itemMinimal = try #require(await xivapi.getItemMinimal(44162))
44+
#expect(itemMinimal.name == "Grade 2 Gemdraught of Strength")
45+
}
46+
47+
@Test("Decode Recipe") func DecodeRecipe() async throws {
48+
let recipe = try #require(await xivapi.getRecipe(35585))
49+
#expect(recipe.itemResult.row_id == 39727)
50+
}
51+
52+
@Test("Decode Map") func DecodeMap() async throws {
53+
let map = try #require(await xivapi.getMap(696))
54+
#expect(map.name == "Thavnair")
55+
}
56+
57+
@Test("Decode Trait") func DecodeTrait() async throws {
58+
let trait = try #require(await xivapi.getTrait(422))
59+
#expect(trait.name == "Enhanced Unmend")
60+
}
61+
62+
@Test("Decode Action") func DecodeAction() async throws {
63+
let action = try #require(await xivapi.getAction(7393))
64+
#expect(action.name == "The Blackest Night")
65+
}
66+
67+
//MARK: other sheets
68+
@Test("Decode AozAction") func DecodeAozAction() async throws { #expect(await xivapi.getSheet(.AozAction, id: 2) as AozAction? != nil) }
69+
@Test("Decode BGM") func DecodeBGM() async throws { #expect(await xivapi.getSheet(.BGM, id: 50) as BGM? != nil) }
70+
@Test("Decode ClassJob") func DecodeClassJob() async throws { #expect(await xivapi.getSheet(.ClassJob, id: 1) as ClassJob? != nil) }
71+
@Test("Decode ContentFinderCondition") func DecodeContentFinderCondition() async throws { #expect(await xivapi.getSheet(.ContentFinderCondition, id: 1) as ContentFinderCondition? != nil) }
72+
@Test("Decode ENpcResident") func DecodeENpcResident() async throws { #expect(await xivapi.getSheet(.ENpcResident, id: 1005634) as ENpcResident? != nil) }
73+
@Test("Decode InstanceContent") func DecodeInstanceContent() async throws { #expect(await xivapi.getSheet(.InstanceContent, id: 1) as InstanceContent? != nil) }
74+
@Test("Decode PvPAction") func DecodePvPAction() async throws { #expect(await xivapi.getSheet(.PvPAction, id: 1) as PvPAction? != nil) }
75+
@Test("Decode Quest") func DecodeQuest() async throws { #expect(await xivapi.getSheet(.Quest, id: 65973) as Quest? != nil) }
76+
@Test("Decode Status") func DecodeStatus() async throws { #expect(await xivapi.getSheet(.Status, id: 1) as XivStatus? != nil) }
77+
@Test("Decode Town") func DecodeTown() async throws { #expect(await xivapi.getSheet(.Town, id: 1) as Town? != nil) }
78+
@Test("Decode TripleTriadCard") func DecodeTripleTriadCard() async throws { #expect(await xivapi.getSheet(.TripleTriadCard, id: 346) as TripleTriadCard? != nil) }
79+
80+
81+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Testing
2+
import xivapi_swift
3+
4+
@Suite("ContentFinderCondition")
5+
struct ContentFinderCondition_Tests {
6+
let xivapi = xivapiClient()
7+
8+
@Test("Dungeon") func ContentFinderCondition() async throws {
9+
let dungeon = try #require(await xivapi.getSheet(.ContentFinderCondition, id: 1) as ContentFinderCondition?)
10+
11+
#expect(dungeon.name == "the Thousand Maws of Toto–Rak")
12+
#expect(dungeon.contentType.fields.Name == "Dungeons")
13+
#expect(dungeon.description == "Named after a man-eating creature from Padjali folklore, the Thousand Maws of Toto-Rak was built on the site of a natural cave system beneath Silent Arbor. Until recently, it held all of Gridania's foulest criminals, from arsonists to poachers, but the completion of a new gaol closer to the city heralded its abandonment.")
14+
#expect(dungeon.image.id == 112005)
15+
}
16+
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Testing
2+
import xivapi_swift
3+
4+
@Suite("Embedded")
5+
struct EmbeddedResources_Tests {
6+
let xivapi = xivapiClient()
7+
8+
@Test("Recipe Lookup") func RecipeLookup() async throws {
9+
let itemRecipes = try #require(await xivapi.getItemRecipes(itemId: 5057)) //Item: Iron Ingot
10+
#expect(itemRecipes == [43, 189]) //Blacksmith, Armorer
11+
}
12+
13+
@Test("All Recipes") func AllRecipes() async throws { #expect(await xivapi.getItemRecipeDict().count > 0) }
14+
15+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import Foundation
2+
import Testing
3+
import xivapi_swift
4+
5+
@Suite("Item")
6+
struct Item_Tests {
7+
let xivapi = xivapiClient()
8+
9+
@Test("Item: Tincture") func ItemTincture() async throws {
10+
let item = try #require(await xivapi.getItem(44162)) //Item: Grade 2 Gemdraught of Strength
11+
12+
try #require(item != nil)
13+
#expect(item.fields.Name == "Grade 2 Gemdraught of Strength")
14+
#expect(item.fields.LevelItem.value == 710)
15+
16+
#expect(item.canBeHq == true)
17+
#expect(item.cooldown == 300)
18+
#expect(item.description == "This diluted brew temporarily increases strength for twice the duration of similar potions.\n\nDuration: 30s")
19+
#expect(item.icon.iconUrl(format: .jpg)?.description == "https://beta.xivapi.com/api/1/asset/ui/icon/020000/020710.tex?format=jpg")
20+
#expect(item.icon.iconUrlHD(format: .jpg)?.description == "https://beta.xivapi.com/api/1/asset/ui/icon/020000/020710_hr1.tex?format=jpg")
21+
22+
#expect(item.levelEquip == 1)
23+
#expect(item.itemLevel == 710)
24+
25+
#expect(item.isAdvancedMeldingPermitted == false)
26+
#expect(item.isCollectable == false)
27+
#expect(item.isCrestWorthy == false)
28+
#expect(item.isGlamorous == false)
29+
#expect(item.isIndisposable == false)
30+
#expect(item.isPvP == false)
31+
#expect(item.isUntradable == false)
32+
33+
#expect(item.name == "Grade 2 Gemdraught of Strength")
34+
#expect(item.priceLow == 95)
35+
#expect(item.priceMid == 99999)
36+
#expect(item.rarity == 1)
37+
38+
#expect(item.stackSize == 999)
39+
40+
#expect(item.itemUICategory.fields?.Name == "Medicine")
41+
#expect(item.additionalData?.sheet == nil)
42+
#expect(item.bonuses.isEmpty == true)
43+
#expect(item.itemFood != nil)
44+
#expect(item.itemEffectNQ == nil)
45+
#expect(item.itemEffectHQ == nil)
46+
47+
}
48+
49+
@Test("Item: MP Potion") func ItemEther() async throws {
50+
let item = try #require(await xivapi.getItem(23168)) //Item: Super-Ether
51+
52+
#expect(item.itemFood == nil)
53+
#expect(item.itemEffectNQ?.isEmpty == false)
54+
#expect(item.itemEffectHQ?.isEmpty == false)
55+
}
56+
57+
@Test("Item: HP Potion") func ItemPotion() async throws {
58+
let item = try #require(await xivapi.getItem(38956))
59+
60+
#expect(item.itemFood == nil)
61+
#expect(item.itemEffectNQ?.isEmpty == false)
62+
#expect(item.itemEffectHQ?.isEmpty == false)
63+
}
64+
65+
@Test("Item: Weapon") func ItemWeapon() async throws {
66+
let item = try #require(await xivapi.getItem(36949))
67+
68+
#expect(item.stats.damagePhys == 120)
69+
}
70+
71+
@Test("Item: Food") func ItemFood() async throws {
72+
let item = try #require(await xivapi.getItem(44175)) //Roast Chicken
73+
let foodId = try #require(item.itemFood)
74+
let food = try #require(await xivapi.getSheet(.ItemFood, id: foodId) as ItemFood?)
75+
76+
#expect(food.bonusesNQ.first?.value == 105)
77+
#expect(food.bonusesHQ.first?.value == 132)
78+
}
79+
80+
@Test("Item: Spiritbond") func ItemFood2() async throws {
81+
let item = try #require(await xivapi.getItem(27960)) //Superior Spiritbond Potion
82+
let foodId = try #require(item.itemFood)
83+
let food = try #require(await xivapi.getSheet(.ItemFood, id: foodId) as ItemFood?)
84+
85+
#expect(food.bonusesNQ.first?.value == 5)
86+
#expect(food.bonusesHQ.first?.value == 6)
87+
}
88+
89+
@Test func ItemMinimal() async throws {
90+
let item = try #require(await xivapi.getItemMinimal(44162))
91+
92+
#expect(item.name == "Grade 2 Gemdraught of Strength")
93+
#expect(item.description.isEmpty == false)
94+
#expect(item.icon.path != nil)
95+
}
96+
}

0 commit comments

Comments
 (0)