Skip to content

Commit

Permalink
feat(examples): Implement a regular UT for RMRK Resource service (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisInSky authored Feb 13, 2024
1 parent acdac38 commit 268e11a
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 4 deletions.
102 changes: 102 additions & 0 deletions examples/rmrk/resource/app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,105 @@ fn resource_storage_data_mut() -> &'static mut ResourceStorageData {
fn resource_storage_admin() -> &'static ActorId {
unsafe { RESOURCE_STORAGE_ADMIN.as_ref().unwrap() }
}

#[cfg(test)]
mod tests {
use super::*;
use catalogs::{
GstdCommonPrimitivesActorId, RmrkCatalogAppErrorsError, RmrkCatalogAppPartsPart,
};
use gstd::{collections::BTreeMap, result::Result as StdResult};
use resources::BasicResource;
use sails_sender::Call;

#[test]
fn test_add_resource_entry() {
let mut resource_storage =
ResourceStorage::new(ExecContextMock { actor_id: 1.into() }, CatalogClientMock);
let resource = Resource::Basic(BasicResource {
src: "src".to_string(),
thumb: None,
metadata_uri: "metadata_uri".to_string(),
});
let (actual_resource_id, actual_resource) = resource_storage
.add_resource_entry(1, resource.clone())
.unwrap();
assert_eq!(actual_resource_id, 1);
assert_eq!(actual_resource, resource);
}

struct ExecContextMock {
actor_id: ActorId,
}

impl ExecContext for ExecContextMock {
type ActorId = ActorId;

fn actor_id(&self) -> &ActorId {
&self.actor_id
}
}

struct CatalogClientMock;

impl CatalogClient for CatalogClientMock {
fn add_parts(
&mut self,
_parts: BTreeMap<u32, RmrkCatalogAppPartsPart>,
) -> Call<StdResult<BTreeMap<u32, RmrkCatalogAppPartsPart>, RmrkCatalogAppErrorsError>>
{
unimplemented!()
}

fn remove_parts(
&mut self,
_part_ids: Vec<u32>,
) -> Call<StdResult<Vec<u32>, RmrkCatalogAppErrorsError>> {
unimplemented!()
}

fn add_equippables(
&mut self,
_part_id: u32,
_collection_ids: Vec<GstdCommonPrimitivesActorId>,
) -> Call<StdResult<(u32, Vec<GstdCommonPrimitivesActorId>), RmrkCatalogAppErrorsError>>
{
unimplemented!()
}

fn remove_equippable(
&mut self,
_part_id: u32,
_collection_id: GstdCommonPrimitivesActorId,
) -> Call<StdResult<(u32, GstdCommonPrimitivesActorId), RmrkCatalogAppErrorsError>>
{
unimplemented!()
}

fn reset_equippables(
&mut self,
_part_id: u32,
) -> Call<StdResult<(), RmrkCatalogAppErrorsError>> {
unimplemented!()
}

fn set_equippables_to_all(
&mut self,
_part_id: u32,
) -> Call<StdResult<(), RmrkCatalogAppErrorsError>> {
unimplemented!()
}

fn part(&self, _part_id: u32) -> Call<Option<RmrkCatalogAppPartsPart>> {
unimplemented!()
}

fn equippable(
&self,
_part_id: u32,
_collection_id: GstdCommonPrimitivesActorId,
) -> Call<StdResult<bool, RmrkCatalogAppErrorsError>> {
unimplemented!()
}
}
}
8 changes: 4 additions & 4 deletions examples/rmrk/resource/app/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ pub type PartId = u32;

pub type ResourceId = u8;

#[derive(Decode, Encode, TypeInfo, Clone, Debug)]
#[derive(Decode, Encode, TypeInfo, Clone, Debug, PartialEq, Eq)]
pub enum Resource {
Basic(BasicResource),
Slot(SlotResource),
Composed(ComposedResource),
}

#[derive(Decode, Encode, TypeInfo, Clone, Debug)]
#[derive(Decode, Encode, TypeInfo, Clone, Debug, PartialEq, Eq)]
pub struct BasicResource {
/// URI like IPFS hash
pub src: String,
Expand All @@ -24,7 +24,7 @@ pub struct BasicResource {
pub metadata_uri: String,
}

#[derive(Decode, Encode, TypeInfo, Clone, Debug)]
#[derive(Decode, Encode, TypeInfo, Clone, Debug, PartialEq, Eq)]
pub struct ComposedResource {
/// URI like ipfs hash
pub src: String,
Expand All @@ -43,7 +43,7 @@ pub struct ComposedResource {
pub parts: Vec<PartId>,
}

#[derive(Decode, Encode, TypeInfo, Clone, Debug)]
#[derive(Decode, Encode, TypeInfo, Clone, Debug, PartialEq, Eq)]
pub struct SlotResource {
/// URI like ipfs hash
pub src: String,
Expand Down

0 comments on commit 268e11a

Please sign in to comment.