@@ -95,6 +95,7 @@ import {
9595 UserTransactionProcessor ,
9696 UserTransactionStatus ,
9797} from '../src/entity/user/UserTransaction' ;
98+ import { Product , ProductType } from '../src/entity/Product' ;
9899
99100jest . mock ( '../src/common/pubsub' , ( ) => ( {
100101 ...( jest . requireActual ( '../src/common/pubsub' ) as Record < string , unknown > ) ,
@@ -7584,3 +7585,166 @@ describe('field language', () => {
75847585 expect ( res . data . post . language ) . toEqual ( 'en' ) ;
75857586 } ) ;
75867587} ) ;
7588+
7589+ describe ( 'featuredAward field' , ( ) => {
7590+ const QUERY = `
7591+ query Post($id: ID!) {
7592+ post(id: $id) {
7593+ featuredAward {
7594+ award {
7595+ id
7596+ name
7597+ image
7598+ value
7599+ }
7600+ }
7601+ }
7602+ }` ;
7603+
7604+ beforeEach ( async ( ) => {
7605+ await saveFixtures ( con , Product , [
7606+ {
7607+ id : '5978781a-0e22-4702-bb32-1c59a13023c4' ,
7608+ name : 'Award 1' ,
7609+ image : 'https://daily.dev/award.jpg' ,
7610+ type : ProductType . Award ,
7611+ value : 42 ,
7612+ } ,
7613+ {
7614+ id : '03916c91-8030-499e-8d3d-ae0a4c065012' ,
7615+ name : 'Award 2' ,
7616+ image : 'https://daily.dev/award.jpg' ,
7617+ type : ProductType . Award ,
7618+ value : 10 ,
7619+ } ,
7620+ {
7621+ id : '24d83ece-1f82-4a82-ae48-85e5b003c9af' ,
7622+ name : 'Award 3' ,
7623+ image : 'https://daily.dev/award.jpg' ,
7624+ type : ProductType . Award ,
7625+ value : 20 ,
7626+ } ,
7627+ ] ) ;
7628+ } ) ;
7629+
7630+ it ( 'should return featuredAward' , async ( ) => {
7631+ const [ transaction , transaction2 , transaction3 ] = await con
7632+ . getRepository ( UserTransaction )
7633+ . save ( [
7634+ {
7635+ processor : UserTransactionProcessor . Njord ,
7636+ receiverId : '1' ,
7637+ status : UserTransactionStatus . Success ,
7638+ productId : '03916c91-8030-499e-8d3d-ae0a4c065012' ,
7639+ senderId : '1' ,
7640+ fee : 0 ,
7641+ value : 10 ,
7642+ valueIncFees : 10 ,
7643+ } ,
7644+ {
7645+ processor : UserTransactionProcessor . Njord ,
7646+ receiverId : '1' ,
7647+ status : UserTransactionStatus . Success ,
7648+ productId : '24d83ece-1f82-4a82-ae48-85e5b003c9af' ,
7649+ senderId : '3' ,
7650+ fee : 0 ,
7651+ value : 20 ,
7652+ valueIncFees : 20 ,
7653+ } ,
7654+ {
7655+ processor : UserTransactionProcessor . Njord ,
7656+ receiverId : '1' ,
7657+ status : UserTransactionStatus . Success ,
7658+ productId : '5978781a-0e22-4702-bb32-1c59a13023c4' ,
7659+ senderId : '2' ,
7660+ fee : 0 ,
7661+ value : 42 ,
7662+ valueIncFees : 42 ,
7663+ } ,
7664+ ] ) ;
7665+
7666+ await con . getRepository ( UserPost ) . save ( [
7667+ {
7668+ postId : 'p1' ,
7669+ userId : transaction . senderId ,
7670+ vote : UserVote . None ,
7671+ hidden : false ,
7672+ flags : {
7673+ awardId : transaction . productId ,
7674+ } ,
7675+ awardTransactionId : transaction . id ,
7676+ } ,
7677+ {
7678+ postId : 'p1' ,
7679+ userId : transaction2 . senderId ,
7680+ vote : UserVote . None ,
7681+ hidden : false ,
7682+ flags : {
7683+ awardId : transaction2 . productId ,
7684+ } ,
7685+ awardTransactionId : transaction2 . id ,
7686+ } ,
7687+ {
7688+ postId : 'p2' ,
7689+ userId : transaction3 . senderId ,
7690+ vote : UserVote . None ,
7691+ hidden : false ,
7692+ flags : {
7693+ awardId : transaction3 . productId ,
7694+ } ,
7695+ awardTransactionId : transaction3 . id ,
7696+ } ,
7697+ ] ) ;
7698+
7699+ const res = await client . query ( QUERY , {
7700+ variables : { id : 'p1' } ,
7701+ } ) ;
7702+
7703+ expect ( res . errors ) . toBeFalsy ( ) ;
7704+
7705+ expect ( res . data . post . featuredAward ) . toMatchObject ( {
7706+ award : {
7707+ id : '24d83ece-1f82-4a82-ae48-85e5b003c9af' ,
7708+ name : 'Award 3' ,
7709+ image : 'https://daily.dev/award.jpg' ,
7710+ value : 20 ,
7711+ } ,
7712+ } ) ;
7713+ } ) ;
7714+
7715+ it ( 'should not return featuredAward if no awards' , async ( ) => {
7716+ const [ transaction ] = await con . getRepository ( UserTransaction ) . save ( [
7717+ {
7718+ processor : UserTransactionProcessor . Njord ,
7719+ receiverId : '1' ,
7720+ status : UserTransactionStatus . Success ,
7721+ productId : '03916c91-8030-499e-8d3d-ae0a4c065012' ,
7722+ senderId : '1' ,
7723+ fee : 0 ,
7724+ value : 10 ,
7725+ valueIncFees : 10 ,
7726+ } ,
7727+ ] ) ;
7728+
7729+ await con . getRepository ( UserPost ) . save ( [
7730+ {
7731+ postId : 'p1' ,
7732+ userId : transaction . senderId ,
7733+ vote : UserVote . None ,
7734+ hidden : false ,
7735+ flags : {
7736+ awardId : transaction . productId ,
7737+ } ,
7738+ awardTransactionId : transaction . id ,
7739+ } ,
7740+ ] ) ;
7741+
7742+ const res = await client . query ( QUERY , {
7743+ variables : { id : 'p2' } ,
7744+ } ) ;
7745+
7746+ expect ( res . errors ) . toBeFalsy ( ) ;
7747+
7748+ expect ( res . data . post . featuredAward ) . toBeNull ( ) ;
7749+ } ) ;
7750+ } ) ;
0 commit comments