From e9ead0d76ef2cc00cc481c8e065a7c9dabeddbf1 Mon Sep 17 00:00:00 2001 From: Mattia M Date: Wed, 9 Aug 2023 00:57:49 +0200 Subject: [PATCH] feat: add comments property to BggPlaysPlayDto Github: Close #49 --- buildtest/cjs/index.test.js | 8 ++++++ buildtest/esm/index.test.js | 8 ++++++ rest.http | 4 +++ src/dto/concrete/subdto/BggPlaySubDtos.ts | 4 +++ .../dtoparser/concrete/BggPlaysDtoParser.ts | 3 ++- test/unit/__fixtures__/response_play.xml | 25 +++++++++++-------- .../utils/reflection/reflectionexport.json | 2 +- 7 files changed, 42 insertions(+), 12 deletions(-) diff --git a/buildtest/cjs/index.test.js b/buildtest/cjs/index.test.js index 1830795..8b7db21 100644 --- a/buildtest/cjs/index.test.js +++ b/buildtest/cjs/index.test.js @@ -122,6 +122,14 @@ describe('BggClient', () => { const validationResult = ValidatorTraverse(dtoList[0], reflectionProperties, reflectionPropertiesExcludable) + expect(validationResult).toStrictEqual([]) + }, 70000); + it('should parse Play dto when xml response is valid with comments', async () => { + + const dtoList = await client.play.query({ username: 'Vitho' }) + + const validationResult = ValidatorTraverse(dtoList[0], reflectionProperties, reflectionPropertiesExcludable) + expect(validationResult).toStrictEqual([]) }, 70000); }); diff --git a/buildtest/esm/index.test.js b/buildtest/esm/index.test.js index 069a726..a42d065 100644 --- a/buildtest/esm/index.test.js +++ b/buildtest/esm/index.test.js @@ -127,6 +127,14 @@ describe('BggClient', () => { const validationResult = ValidatorTraverse(dtoList[0], reflectionProperties, reflectionPropertiesExcludable) + expect(validationResult).toStrictEqual([]) + }, 70000); + it('should parse Play dto when xml response is valid with comments', async () => { + + const dtoList = await client.play.query({ username: 'Vitho' }) + + const validationResult = ValidatorTraverse(dtoList[0], reflectionProperties, reflectionPropertiesExcludable) + expect(validationResult).toStrictEqual([]) }, 70000); }); diff --git a/rest.http b/rest.http index 67f947c..5e3f93a 100644 --- a/rest.http +++ b/rest.http @@ -25,6 +25,10 @@ GET https://www.boardgamegeek.com/xmlapi2/collection?username=Vitho HTTP/1.1 GET https://www.boardgamegeek.com/xmlapi2/plays?username=mattiabanned HTTP/1.1 +### plays with comme + +GET https://www.boardgamegeek.com/xmlapi2/plays?username=Vitho HTTP/1.1 + ### thread GET https://www.boardgamegeek.com/xmlapi2/thread?id=1082079 HTTP/1.1 diff --git a/src/dto/concrete/subdto/BggPlaySubDtos.ts b/src/dto/concrete/subdto/BggPlaySubDtos.ts index bd50632..515d140 100644 --- a/src/dto/concrete/subdto/BggPlaySubDtos.ts +++ b/src/dto/concrete/subdto/BggPlaySubDtos.ts @@ -53,6 +53,10 @@ export class BggPlaysPlayDto { }) item!: BggPlaysPlayItemDto; + @JsonProperty() + @JsonClassType({ type: () => [String] }) + comments!: string; + @JsonProperty() @JsonClassType({ type: () => [BggPlaysPlayItemDto] }) @JsonAlias({ values: ["players"] }) diff --git a/src/dto/dtoparser/concrete/BggPlaysDtoParser.ts b/src/dto/dtoparser/concrete/BggPlaysDtoParser.ts index ed415c1..e69b879 100644 --- a/src/dto/dtoparser/concrete/BggPlaysDtoParser.ts +++ b/src/dto/dtoparser/concrete/BggPlaysDtoParser.ts @@ -1,9 +1,10 @@ -import { JsonParser } from "jackson-js"; +import { JsonParser, ObjectMapper } from "jackson-js"; import { BggPlayDto } from "../../concrete"; import { IDtoParser } from "../interface"; export class BggPlayDtoParser implements IDtoParser { parser: JsonParser; + mapper: ObjectMapper; constructor() { this.parser = new JsonParser(); } diff --git a/test/unit/__fixtures__/response_play.xml b/test/unit/__fixtures__/response_play.xml index 5d05e06..0f1f733 100644 --- a/test/unit/__fixtures__/response_play.xml +++ b/test/unit/__fixtures__/response_play.xml @@ -1,12 +1,17 @@ - - - - - - - - - - \ No newline at end of file + + + + + + + + + this is the first comment line +this is the second comment line + + + + + diff --git a/test/unit/utils/reflection/reflectionexport.json b/test/unit/utils/reflection/reflectionexport.json index f3b8f04..7eda134 100644 --- a/test/unit/utils/reflection/reflectionexport.json +++ b/test/unit/utils/reflection/reflectionexport.json @@ -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",[]],["BggUserDto",["id","name","firstname","lastname","avatarlink","yearregistered","lastlogin","stateorprovince","country","webaddress","xboxaccount","wiiaccount","psnaccount","battlenetaccount","steamaccount","traderating"]],["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",[]],["BggCollectionItemStatsDto",["rating","usersrated","average","bayesaverage","stddev","median","ranks"]],["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"]]] \ No newline at end of file +[["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",[]],["BggUserDto",["id","name","firstname","lastname","avatarlink","yearregistered","lastlogin","stateorprovince","country","webaddress","xboxaccount","wiiaccount","psnaccount","battlenetaccount","steamaccount","traderating"]],["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",[]],["BggCollectionItemStatsDto",["rating","usersrated","average","bayesaverage","stddev","median","ranks"]],["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","comments","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"]]] \ No newline at end of file