Skip to content

Commit

Permalink
feat: Start v2 api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
octfx committed Aug 2, 2023
1 parent 60dc587 commit 893963b
Show file tree
Hide file tree
Showing 32 changed files with 76,858 additions and 26 deletions.
6 changes: 5 additions & 1 deletion .env.ci
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ APP_URL=http://127.0.0.1:8000
DB_CONNECTION=sqlite
DB_DATABASE=db.sqlite

ADMIN_AUTH_USE_STUB=true
ADMIN_AUTH_USE_STUB=true


SC_DATA_VERSION=9.99.9
SC_DATA_PATH=framework/testing/scunpacked
4 changes: 3 additions & 1 deletion app/Console/Commands/SC/ImportItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use JsonException;

Expand Down Expand Up @@ -50,7 +51,8 @@ public function handle(): int
$labels = (new Labels())->getData();
$manufacturers = (new Manufacturers())->getData();

$files = Storage::allFiles('api/scunpacked-data/items') + Storage::allFiles('api/scunpacked-data/ships');

$files = File::allFiles(scdata('items')) + Storage::allFiles(scdata('ships'));

if ($this->option('skipItems') === false) {
collect($files)
Expand Down
14 changes: 7 additions & 7 deletions app/Console/Commands/SC/ImportVehicles.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ImportVehicles extends AbstractQueueCommand
public function handle()
{
try {
$vehicles = File::get(storage_path('app/api/scunpacked-data/v2/ships.json'));
$vehicles = File::get(scdata('v2/ships.json'));
} catch (FileNotFoundException $e) {
$this->error('ships.json not found. Did you clone scunpacked?');
return Command::FAILURE;
Expand Down Expand Up @@ -69,15 +69,15 @@ public function handle()
return $this->isNotIgnoredClass($vehicle['ClassName']);
})
->map(function (array $vehicle) {
$vehicle['filePathV2'] = sprintf(
'api/scunpacked-data/v2/ships/%s-raw.json',
$vehicle['filePathV2'] = scdata(sprintf(
'v2/ships/%s-raw.json',
strtolower($vehicle['ClassName'])
);
));

$vehicle['filePath'] = sprintf(
'api/scunpacked-data/ships/%s.json',
$vehicle['filePath'] = scdata(sprintf(
'ships/%s.json',
strtolower($vehicle['ClassName'])
);
));

return $vehicle;
})->each(function (array $vehicle) {
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/SC/Import/Vehicle.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function handle(): void
$vehicle = $this->shipData;

try {
$rawData = File::get(storage_path(sprintf('app/%s', $vehicle['filePathV2'])));
$rawData = File::get($vehicle['filePathV2']);

$vehicle['rawData'] = json_decode($rawData, true, 512, JSON_THROW_ON_ERROR);
} catch (FileNotFoundException | JsonException $e) {
Expand Down
4 changes: 2 additions & 2 deletions app/Models/SC/Char/Clothing/Clothing.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public function getTempResistanceMinAttribute()
return $this->resistances()
->where('type', 'temp_min')
->first()
->threshold;
?->threshold;
}

public function getTempResistanceMaxAttribute()
{
return $this->resistances()
->where('type', 'temp_max')
->first()
->threshold;
?->threshold;
}

public function getDamageReductionAttribute()
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Parser/SC/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class Item extends AbstractCommodityItem
*/
public function __construct(string $fileName, Collection $labels, Collection $manufacturers)
{
$items = File::get(storage_path(sprintf('app/%s', $fileName)));
$items = File::get($fileName);
$this->item = collect(json_decode($items, true, 512, JSON_THROW_ON_ERROR));
$this->labels = $labels;
$this->manufacturers = $manufacturers;
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Parser/SC/Labels.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class Labels
*/
public function __construct()
{
$items = File::get(storage_path('app/api/scunpacked-data/labels.json'));
$items = File::get(scdata('labels.json'));
$this->labels = collect(json_decode($items, true, 512, JSON_THROW_ON_ERROR));
}

Expand Down
2 changes: 1 addition & 1 deletion app/Services/Parser/SC/Manufacturers.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class Manufacturers
*/
public function __construct()
{
$items = File::get(storage_path('app/api/scunpacked-data/manufacturers.json'));
$items = File::get(scdata('manufacturers.json'));
$this->manufacturers = collect(json_decode($items, true, 512, JSON_THROW_ON_ERROR));
}

Expand Down
2 changes: 1 addition & 1 deletion app/Services/Parser/SC/Shops/Shops.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class Shops
*/
public function __construct()
{
$items = File::get(storage_path('app/api/scunpacked-data/shops.json'));
$items = File::get(scdata('shops.json'));
$this->shops = collect(json_decode($items, true, 512, JSON_THROW_ON_ERROR));
$this->addShops();
$this->mapped = collect();
Expand Down
12 changes: 12 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@ function str_split_unicode(string $str, int $length = 1)
return $tmp;
}
}

if (!function_exists('scdata')) {
/**
* Generate a link to the scunpacked data
*
* @param string $path
* @return string
*/
function scdata( string $path ): string {
return storage_path(sprintf('%s/%s', config('api.sc_data_path' ), ltrim($path, '/')));
}
}
1 change: 1 addition & 0 deletions config/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
'rsi_url' => env('RSI_URL', 'https://robertsspaceindustries.com'),

'sc_data_version' => env('SC_DATA_VERSION'),
'sc_data_path' => env('SC_DATA_PATH', 'app/api/scunpacked-data'),
];
2 changes: 1 addition & 1 deletion storage/app/api/scunpacked-data
Submodule scunpacked-data updated 20062 files
216 changes: 216 additions & 0 deletions storage/framework/testing/scunpacked/items/987_jacket_01_01_01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
{
"Raw": {
"Entity": {
"StaticEntityClassData": {
"DefaultEntitlementEntityParams": {
"entitlementPolicy": "8a1fdd48-7896-4774-a110-2466190e1a07"
}
},
"tags": [
{
"value": "65124877-3571-4f63-b4a5-650a79e5bfb6"
},
{
"value": "bf3c7235-1d79-468e-b981-2494f00b8f18"
},
{
"value": "532b3340-6cc9-4124-b822-8a422a89f2b6"
},
{
"value": "59ca5e36-b9a2-4459-ad0e-5745bcf5d899"
},
{
"value": "2ebe6f26-d592-488a-8625-d42ef5fec31c"
},
{
"value": "7f55d7e2-5f7f-470d-b6bb-c89196ed7b0e"
},
{
"value": "bed8e09b-a5f2-4f4e-9be9-ab618ebfbd58"
}
],
"Components": {
"SAttachableComponentParams": {
"AttachDef": {
"Type": "Char_Clothing_Torso_1",
"SubType": "UNDEFINED",
"Size": 1,
"Grade": 1,
"Manufacturer": "3b54a8cc-5700-45f1-940a-2436b213926f",
"Tags": "987_jacket set_01 Color_01",
"RequiredTags": "",
"DisplayType": "",
"Localization": {
"Name": "@item_Name_987_Jacket_01_01_01",
"Description": "@item_Desc_987_Jacket_01_01_01"
},
"inventoryOccupancyVolume": {
"SMicroCargoUnit": {
"microSCU": 8700.0
}
},
"inventoryOccupancyDimensions": {
"x": 0.356,
"y": 0.183,
"z": 0.166
},
"inventoryOccupancyDimensionsUIOverride": {
"Vec3": {
"x": 0.75,
"y": 0.75,
"z": 0.75
}
}
}
},
"SEntityInteractableParams": {
"Interactable": {
"SharedInteractions": [
{
"Name": "Grab",
"RoomTag": "00000000-0000-0000-0000-000000000000",
"UsableTag": "00000000-0000-0000-0000-000000000000",
"DisplayName": "@interaction_grab",
"DisplayType": "Show",
"GenericCursor": "Grab",
"FocusModeOnly": false,
"Sendable": false,
"Linkable": false,
"LockedByLinks": false,
"RequiresAuthorizedUser": false,
"available": true
},
{
"Name": "Carry",
"RoomTag": "00000000-0000-0000-0000-000000000000",
"UsableTag": "00000000-0000-0000-0000-000000000000",
"DisplayName": "@interaction_carry",
"DisplayType": "Show",
"GenericCursor": "Grab",
"FocusModeOnly": false,
"Sendable": false,
"Linkable": false,
"LockedByLinks": false,
"RequiresAuthorizedUser": false,
"available": true
},
{
"Name": "Drop",
"RoomTag": "00000000-0000-0000-0000-000000000000",
"UsableTag": "00000000-0000-0000-0000-000000000000",
"DisplayName": "@interaction_drop",
"DisplayType": "Show",
"GenericCursor": "SingleAction",
"FocusModeOnly": false,
"Sendable": false,
"Linkable": false,
"LockedByLinks": false,
"RequiresAuthorizedUser": false,
"available": true
},
{
"Name": "Place",
"RoomTag": "00000000-0000-0000-0000-000000000000",
"UsableTag": "00000000-0000-0000-0000-000000000000",
"DisplayName": "@interaction_place",
"DisplayType": "Show",
"GenericCursor": "SingleAction",
"FocusModeOnly": false,
"Sendable": false,
"Linkable": false,
"LockedByLinks": false,
"RequiresAuthorizedUser": false,
"available": true
},
{
"Name": "Store",
"RoomTag": "00000000-0000-0000-0000-000000000000",
"UsableTag": "00000000-0000-0000-0000-000000000000",
"DisplayName": "@interaction_store",
"DisplayType": "Show",
"GenericCursor": "SingleAction",
"FocusModeOnly": false,
"Sendable": false,
"Linkable": false,
"LockedByLinks": false,
"RequiresAuthorizedUser": false,
"available": true
},
{
"Name": "Equip",
"RoomTag": "00000000-0000-0000-0000-000000000000",
"UsableTag": "00000000-0000-0000-0000-000000000000",
"DisplayName": "@interaction_equip",
"DisplayType": "Show",
"GenericCursor": "SingleAction",
"FocusModeOnly": false,
"Sendable": false,
"Linkable": false,
"LockedByLinks": false,
"RequiresAuthorizedUser": false,
"available": true
},
{
"Name": "OpenExternalInventory",
"RoomTag": "00000000-0000-0000-0000-000000000000",
"UsableTag": "00000000-0000-0000-0000-000000000000",
"DisplayName": "@interaction_open",
"DisplayType": "Show",
"GenericCursor": "SingleAction",
"FocusModeOnly": false,
"Sendable": false,
"Linkable": false,
"LockedByLinks": false,
"RequiresAuthorizedUser": false,
"available": true
}
]
}
},
"SCItemClothingParams": {
"TemperatureResistance": {
"MinResistance": 2.0,
"MaxResistance": 32.0
}
},
"SItemPortContainerComponentParams": {
"PortFlags": "",
"PortTags": "",
"RequiredItemTags": "",
"Ports": [
{
"Name": "Material_Variant",
"DisplayName": "Material_Variant",
"PortTags": "",
"RequiredPortTags": "",
"Flags": "nontransferable ",
"MinSize": 1,
"MaxSize": 1,
"InteractionPointSize": -1.0,
"DefaultWeaponGroup": "UNDEFINED",
"Types": [
{
"Type": "Paints",
"SubTypes": []
}
]
}
]
},
"SCItemInventoryContainerComponentParams": {
"containerParams": "f4656fda-387e-46fe-8860-e8bf95380f64"
}
},
"ClassName": "987_jacket_01_01_01",
"__ref": "9c478af1-acfd-4e88-b065-c5ebeb05f507",
"__type": "EntityClassDefinition"
}
},
"inventoryContainer": {
"SCU": 0.001,
"x": 0.365,
"y": 0.365,
"z": 0.1825,
"unit": 6.0
}
}
Loading

0 comments on commit 893963b

Please sign in to comment.