@@ -642,6 +642,18 @@ describe('archive queries', () => {
642642 }
643643 ` ;
644644
645+ const featuredArchivesQuery = `
646+ query FeaturedArchives($subjectType: String!, $subjectId: String!) {
647+ featuredArchives(subjectType: $subjectType, subjectId: $subjectId) {
648+ id
649+ scopeType
650+ scopeId
651+ periodType
652+ periodStart
653+ }
654+ }
655+ ` ;
656+
645657 beforeEach ( async ( ) => {
646658 await materializePeriodArchives ( {
647659 con,
@@ -704,6 +716,52 @@ describe('archive queries', () => {
704716 ] ) ;
705717 } ) ;
706718
719+ it ( 'should return all relevant archives for a featured post' , async ( ) => {
720+ const res = await client . query ( featuredArchivesQuery , {
721+ variables : {
722+ subjectType : ArchiveSubjectType . Post ,
723+ subjectId : 'post-6' ,
724+ } ,
725+ } ) ;
726+
727+ expect ( res . errors ) . toBeFalsy ( ) ;
728+ expect ( res . data . featuredArchives ) . toEqual ( [
729+ {
730+ id : expect . any ( String ) ,
731+ scopeType : ArchiveScopeType . Global ,
732+ scopeId : null ,
733+ periodType : ArchivePeriodType . Month ,
734+ periodStart : marchPeriodStart . toISOString ( ) ,
735+ } ,
736+ {
737+ id : expect . any ( String ) ,
738+ scopeType : ArchiveScopeType . Source ,
739+ scopeId : 'source-a' ,
740+ periodType : ArchivePeriodType . Month ,
741+ periodStart : marchPeriodStart . toISOString ( ) ,
742+ } ,
743+ {
744+ id : expect . any ( String ) ,
745+ scopeType : ArchiveScopeType . Tag ,
746+ scopeId : 'webdev' ,
747+ periodType : ArchivePeriodType . Month ,
748+ periodStart : marchPeriodStart . toISOString ( ) ,
749+ } ,
750+ ] ) ;
751+ } ) ;
752+
753+ it ( 'should return an empty list when no archives exist for the requested subject type' , async ( ) => {
754+ const res = await client . query ( featuredArchivesQuery , {
755+ variables : {
756+ subjectType : ArchiveSubjectType . User ,
757+ subjectId : 'author-good' ,
758+ } ,
759+ } ) ;
760+
761+ expect ( res . errors ) . toBeFalsy ( ) ;
762+ expect ( res . data . featuredArchives ) . toEqual ( [ ] ) ;
763+ } ) ;
764+
707765 it ( 'should validate that tag archives require a scopeId' , async ( ) =>
708766 testQueryErrorCode (
709767 client ,
@@ -739,4 +797,16 @@ describe('archive queries', () => {
739797 'GRAPHQL_VALIDATION_FAILED' ,
740798 'month must not be set for yearly archives' ,
741799 ) ) ;
800+
801+ it ( 'should accept other archive subject types even when no results exist' , async ( ) => {
802+ const res = await client . query ( featuredArchivesQuery , {
803+ variables : {
804+ subjectType : ArchiveSubjectType . Squad ,
805+ subjectId : 'source-a' ,
806+ } ,
807+ } ) ;
808+
809+ expect ( res . errors ) . toBeFalsy ( ) ;
810+ expect ( res . data . featuredArchives ) . toEqual ( [ ] ) ;
811+ } ) ;
742812} ) ;
0 commit comments