Skip to content

Commit

Permalink
Merge pull request #34 from LearningProcesss/32-error-unknown-propert…
Browse files Browse the repository at this point in the history
…y-wantpartslist-for-bggcollectionitemdto

feat: add wantpartslist,haspartslist to BggCollectionItemDto
  • Loading branch information
LearningProcesss authored Jul 10, 2022
2 parents f319091 + 2626e25 commit 590aac5
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 156 deletions.
11 changes: 9 additions & 2 deletions buildtest/cjs/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ beforeAll(() => {
describe('BggClient', () => {
describe('BggThingClient', () => {
it('should fetch and deserialize all data when request has all params', async () => {
const dtoList = await client.thing.query({ id: 174430, videos: 1, comments: 1, marketplace: 1, stats: 1, versions: 1, type: "boardgame" })

const validationResult = ValidatorTraverse(dtoList[0], reflectionProperties, reflectionPropertiesExcludable)

expect(validationResult).toStrictEqual([])
}, 70000);
it('should fetch and deserialize all data when request has not all params', async () => {
const dtoList = await client.thing.query({ id: 174430, videos: 1, comments: 1, marketplace: 1, stats: 1, type: "boardgame" })

const validationResult = ValidatorTraverse(dtoList[0], reflectionProperties, reflectionPropertiesExcludable)

expect(validationResult).toStrictEqual([])
}, 70000);
});
Expand Down
2 changes: 1 addition & 1 deletion rest.http
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GET https://www.boardgamegeek.com/xmlapi2/family?id=8374&type=boardgamefamily

### collection

GET https://www.boardgamegeek.com/xmlapi2/collection?username=mattiabanned HTTP/1.1
GET https://www.boardgamegeek.com/xmlapi2/collection?username=mattiabanned&version=1 HTTP/1.1

### plays

Expand Down
2 changes: 1 addition & 1 deletion src/dto/concrete/BggThingDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ export class BggThingDto implements IBggDto {
//eslint-disable-next-line @typescript-eslint/no-explicit-any
using: (items: any[]) => items[0].item
})
versions!: BggThingVersionDto[];
versions: BggThingVersionDto[];
}
34 changes: 21 additions & 13 deletions src/dto/concrete/subdto/BggCollectionItemDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,71 @@ export class BggCollectionItemDto {
@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_objectid"] })
objectid!: number;
objectid: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
@JsonAlias({ values: ["@_collid"] })
collid!: number;
collid: number;

@JsonProperty()
@JsonClassType({ type: () => [String] })
@JsonAlias({ values: ["@_objecttype"] })
objecttype!: string;
objecttype: string;

@JsonProperty()
@JsonClassType({ type: () => [String] })
@JsonAlias({ values: ["@_subtype"] })
subtype!: string;
subtype: string;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
yearpublished!: number;
yearpublished: number;

@JsonProperty()
@JsonClassType({ type: () => [Number] })
numplays!: number;
numplays: number;

@JsonProperty()
@JsonClassType({ type: () => [String] })
image!: string;
image: string;

@JsonProperty()
@JsonClassType({ type: () => [String] })
thumbnail!: string;
thumbnail: string;

@JsonProperty()
@JsonClassType({ type: () => [String] })
comment!: string;
comment: string;

@JsonProperty()
@JsonClassType({ type: () => [String] })
wishlistcomment!: string;
wishlistcomment: string;

@JsonProperty()
@JsonClassType({ type: () => [String] })
@JsonDeserialize({
using: (value: []) => value.map(item => item['#text'])[0]
})
name!: string;
name: string;

@JsonProperty()
@JsonClassType({ type: () => [String] })
originalname!: string;
originalname: string;

@JsonProperty()
@JsonClassType({ type: () => [String] })
wantpartslist: string;

@JsonProperty()
@JsonClassType({ type: () => [String] })
haspartslist: string;

@JsonProperty()
@JsonClassType({ type: () => [BggCollectionItemStatusDto] })
@JsonDeserialize({
using: (value: any[]) => value[0]
})
@JsonManagedReference()
status!: BggCollectionItemStatusDto;
status: BggCollectionItemStatusDto;
}
306 changes: 172 additions & 134 deletions test/unit/__fixtures__/response_collection.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/unit/dtoparser/BggDtoParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('BggDtoParsers', () => {
});
});
describe('BggCollectionDtoParser', () => {
it('should parse Thing dto when xml response is valid', async () => {
it('should parse Collection dto when xml response is valid', async () => {

const xmlResponse: string = TextResponseByEndpoint['https://www.boardgamegeek.com/xmlapi2/collection?username=mattiabanned'];

Expand All @@ -188,7 +188,7 @@ describe('BggDtoParsers', () => {

const dtoList = await dtoParser.jsonToDto(jsonData);

const dto: BggCollectionDto = dtoList[0]
const dto: BggCollectionDto = dtoList[0];

const validationResult = ValidatorTraverse(dto, reflectionProperties, reflectionPropertiesExcludable)

Expand Down
2 changes: 1 addition & 1 deletion test/unit/utils/reflection/reflectionexport.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[["BggArticleDto",["id","username","body","subject","numedits","editdate","postdate","link"]],["BggCollectionDto",["id","totalitems","pubdate","items"]],["BggFamilyDto",["name","description","thumbnail","image","id","type","things"]],["BggForumDto",["id","lastpostdate","noposting","numthreads","numposts","title","threads"]],["BggForumThreadDto",["id","numarticles","subject","author","postdate","lastpostdate"]],["BggForumlistDto",["id","type","forums"]],["BggForumlistForumDto",["id","groupid","lastpostdate","noposting","numthreads","numposts","title","description"]],["BggGuildDto",["id","name","created","category","website","manager","description","members"]],["BggGuildMemberDto",["name","date"]],["BggGuildMemeberDto",["name","date"]],["BggHotDto",["id","rank","thumbnail","name","yearpublished"]],["BggPlayDto",["id","userid","total","page","username","plays"]],["BggSearchDto",["id","total","items"]],["BggThingDto",["id","name","type","description","thumbnail","image","yearpublished","minplayers","maxplayers","playingtime","minplaytime","maxplaytime","minage","links","statistics","videos","comments","marketplacelistings","polls","versions"]],["BggThreadDto",["id","link","numarticles","subject","articles"]],["BggUserDto",["id","name","firstname","lastname","avatarlink","yearregistered","lastlogin","stateorprovince","country","webaddress","xboxaccount","wiiaccount","psnaccount","battlenetaccount","steamaccount","traderating","marketrating"]],["index",[]],["BggStatisticsPaginatedDto",["page","ratings"]],["BggStatisticsRatingDto",["average","usersrated","bayesaverage","stddev","median","owned","trading","wanting","wishing","numcomments","numweights","averageweight","ranks"]],["BggStatisticsRatingRanksDto",["type","id","name","friendlyname","value","bayesaverage"]],["BggThingCommentDto",["value","username","rating"]],["BggThingCommentPaginatedDto",["page","totalitems","items"]],["BggThingVideoDto",["category","language","link","postdate","title","username","id","userid"]],["BggThingVideoPaginatedDto",["total","items"]],["BggCollectionItemDto",["objectid","collid","objecttype","subtype","yearpublished","numplays","image","thumbnail","comment","wishlistcomment","name","originalname","status"]],["BggCollectionItemStatusDto",["own","prevowned","fortrade","want","wanttoplay","wanttobuy","wishlist","wishlistpriority","preordered","lastmodified"]],["BggLinkDto",["id","type","value","inbound"]],["BggPlaySubDtos",["id","userid","date","quantity","length","incomplete","nowinstats","location","item","players"]],["BggPlaysPlayItemDto",["name","objecttype","objectid","subtypes"]],["BggPlaysPlayItemSubtypes",["value"]],["BggPlaysPlayPlayerDto",["color","name","new","rating","score","startposition","userid","username","win"]],["BggPollDto",["name","title","totalvotes","results"]],["BggPollResultDto",["numplayers","resultItemList"]],["BggPollResultItemDto",["level","value","numvotes"]],["BggSearchItemDto",["id","type","name","yearpublished"]],["BggThingMarketlistingsDto",["condition","link","listdate","notes","price"]],["BggThingVersionDto",["type","id","thumbnail","image","links","name","yearpublished","productcode","width","length","depth","weight"]]]
[["BggArticleDto",["id","username","body","subject","numedits","editdate","postdate","link"]],["BggCollectionDto",["id","totalitems","pubdate","items"]],["BggFamilyDto",["name","description","thumbnail","image","id","type","things"]],["BggForumDto",["id","lastpostdate","noposting","numthreads","numposts","title","threads"]],["BggForumThreadDto",["id","numarticles","subject","author","postdate","lastpostdate"]],["BggForumlistDto",["id","type","forums"]],["BggForumlistForumDto",["id","groupid","lastpostdate","noposting","numthreads","numposts","title","description"]],["BggGuildDto",["id","name","created","category","website","manager","description","members"]],["BggGuildMemberDto",["name","date"]],["BggGuildMemeberDto",["name","date"]],["BggHotDto",["id","rank","thumbnail","name","yearpublished"]],["BggPlayDto",["id","userid","total","page","username","plays"]],["BggSearchDto",["id","total","items"]],["BggThingDto",["id","name","type","description","thumbnail","image","yearpublished","minplayers","maxplayers","playingtime","minplaytime","maxplaytime","minage","links","statistics","videos","comments","marketplacelistings","polls"]],["BggThreadDto",["id","link","numarticles","subject","articles"]],["BggUserDto",["id","name","firstname","lastname","avatarlink","yearregistered","lastlogin","stateorprovince","country","webaddress","xboxaccount","wiiaccount","psnaccount","battlenetaccount","steamaccount","traderating","marketrating"]],["index",[]],["BggStatisticsPaginatedDto",["page","ratings"]],["BggStatisticsRatingDto",["average","usersrated","bayesaverage","stddev","median","owned","trading","wanting","wishing","numcomments","numweights","averageweight","ranks"]],["BggStatisticsRatingRanksDto",["type","id","name","friendlyname","value","bayesaverage"]],["BggThingCommentDto",["value","username","rating"]],["BggThingCommentPaginatedDto",["page","totalitems","items"]],["BggThingVideoDto",["category","language","link","postdate","title","username","id","userid"]],["BggThingVideoPaginatedDto",["total","items"]],["BggCollectionItemDto",[]],["BggCollectionItemStatusDto",["own","prevowned","fortrade","want","wanttoplay","wanttobuy","wishlist","wishlistpriority","preordered","lastmodified"]],["BggLinkDto",["id","type","value","inbound"]],["BggPlaySubDtos",["id","userid","date","quantity","length","incomplete","nowinstats","location","item","players"]],["BggPlaysPlayItemDto",["name","objecttype","objectid","subtypes"]],["BggPlaysPlayItemSubtypes",["value"]],["BggPlaysPlayPlayerDto",["color","name","new","rating","score","startposition","userid","username","win"]],["BggPollDto",["name","title","totalvotes","results"]],["BggPollResultDto",["numplayers","resultItemList"]],["BggPollResultItemDto",["level","value","numvotes"]],["BggSearchItemDto",["id","type","name","yearpublished"]],["BggThingMarketlistingsDto",["condition","link","listdate","notes","price"]],["BggThingVersionDto",["type","id","thumbnail","image","links","name","yearpublished","productcode","width","length","depth","weight"]]]
1 change: 1 addition & 0 deletions test/unit/utils/validator/IPropertyResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export interface IPropertyResult {
message: string;
valid: boolean;
objectType: string;
data?: any;
}
2 changes: 1 addition & 1 deletion test/unit/utils/validator/ValidatorTraverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ValidatorTraverse = (object: any, reflectionProperties: Map<string,

for (const property of properties) {
if ((typeof object[property] !== 'object') && (!object.hasOwnProperty(property) || object[property] === undefined)) {
result.push({ valid: false, property, message: `required ${property} is missing or undefined.`, objectType: currentType });
result.push({ valid: false, property, message: `required ${property} is missing or undefined.`, objectType: currentType, data: object });
}
else if ((typeof object[property] === 'object' && object[property] !== null)) {
ValidatorTraverse(object[property], reflectionProperties, reflectionPropertiesExcludable, result);
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"forceConsistentCasingInFileNames": true,
// `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc`
// "noEmit": true,
"experimentalDecorators": true
"experimentalDecorators": true,
"strictPropertyInitialization": false
},
"exclude": [
"node_modules"
Expand Down

0 comments on commit 590aac5

Please sign in to comment.