@@ -4,15 +4,20 @@ import { afterAll, beforeAll, expect, test, vi } from 'vitest';
44import { ResponseAppData } from '@/config/appDataTypes' ;
55
66import { mockItem , mockMembers } from '../../mocks/db' ;
7- import { buildMockResponses } from '../../mocks/mockResponses' ;
7+ import {
8+ buildMockBotResponses ,
9+ buildMockResponses ,
10+ } from '../../mocks/mockResponses' ;
811import {
912 extractNResponsesThatDontHaveMemberAsCreator ,
1013 filterBotResponses ,
1114 recursivelyCreateAllPartiallyBlindSets ,
1215} from './responses' ;
1316
14- const getMapResponses = ( ) : Map < string , ResponseAppData > => {
15- const mockResponses = buildMockResponses ( mockItem , mockMembers ) ;
17+ const getMapResponses = (
18+ responsesAppData : ResponseAppData [ ] ,
19+ ) : Map < string , ResponseAppData > => {
20+ const mockResponses = responsesAppData ;
1621 return new Map ( mockResponses . map ( ( r ) => [ r . id , r ] ) ) ;
1722} ;
1823
@@ -24,15 +29,19 @@ afterAll(() => {
2429} ) ;
2530
2631test ( 'the mocks are good' , ( ) => {
27- const mapResponses = getMapResponses ( ) ;
32+ const mapResponses = getMapResponses (
33+ buildMockResponses ( mockItem , mockMembers ) ,
34+ ) ;
2835 expect ( mapResponses ) . to . be . a ( 'map' ) ;
2936 expect ( mapResponses ) . not . toBeUndefined ( ) ;
3037 // This value should more or less correspond to the mocks.
3138 expect ( mapResponses . size ) . to . be . greaterThanOrEqual ( 12 ) ;
3239} ) ;
3340
3441test ( 'the response map is passed by reference and remains the same' , ( ) => {
35- const mapResponses = getMapResponses ( ) ;
42+ const mapResponses = getMapResponses (
43+ buildMockResponses ( mockItem , mockMembers ) ,
44+ ) ;
3645
3746 const [ , newMapR ] = extractNResponsesThatDontHaveMemberAsCreator (
3847 mapResponses ,
@@ -43,7 +52,9 @@ test('the response map is passed by reference and remains the same', () => {
4352} ) ;
4453
4554test ( 'extracting two responses' , ( ) => {
46- const mapResponses = getMapResponses ( ) ;
55+ const mapResponses = getMapResponses (
56+ buildMockResponses ( mockItem , mockMembers ) ,
57+ ) ;
4758 const n = 2 ;
4859 const initialSize = mapResponses . size ;
4960
@@ -57,7 +68,9 @@ test('extracting two responses', () => {
5768} ) ;
5869
5970test ( 'extracting zero responses gives empty array' , ( ) => {
60- const mapResponses = getMapResponses ( ) ;
71+ const mapResponses = getMapResponses (
72+ buildMockResponses ( mockItem , mockMembers ) ,
73+ ) ;
6174 const copyOfMapResponses = cloneDeep ( mapResponses ) ;
6275 const n = 0 ;
6376
@@ -66,12 +79,14 @@ test('extracting zero responses gives empty array', () => {
6679 n ,
6780 mockMembers [ 0 ] . id ,
6881 ) ;
69- expect ( r ) . to . be . empty ( '' ) ;
82+ expect ( r ) . to . have . length ( 0 ) ;
7083 expect ( newMapR ) . to . be . deep . equals ( copyOfMapResponses ) ;
7184} ) ;
7285
7386test ( 'extracting more responses than available gives all available' , ( ) => {
74- const mapResponses = getMapResponses ( ) ;
87+ const mapResponses = getMapResponses (
88+ buildMockResponses ( mockItem , mockMembers ) ,
89+ ) ;
7590 const n = mapResponses . size + 2 ;
7691 const accountId = mockMembers [ 0 ] . id ;
7792
@@ -86,22 +101,53 @@ test('extracting more responses than available gives all available', () => {
86101 . that . does . not . include ( false ) ;
87102} ) ;
88103
89- test ( 'recursively create all sets' , ( ) => {
90- const mapResponses = getMapResponses ( ) ;
104+ test ( 'recursively create all sets with no bot responses' , ( ) => {
105+ const mapResponses = getMapResponses (
106+ buildMockResponses ( mockItem , mockMembers ) ,
107+ ) ;
91108 const participantIterator = mockMembers . entries ( ) ;
92109 const sets = recursivelyCreateAllPartiallyBlindSets (
93110 participantIterator ,
94111 mapResponses ,
95112 new Map ( ) ,
96113 3 ,
114+ 0 ,
115+ ) ;
116+ expect ( sets . size ) . not . toBe ( 0 ) ;
117+ expect ( sets ) . to . have . keys ( mockMembers . map ( ( { id } ) => id ) ) ;
118+ mockMembers . forEach ( ( { id } ) => {
119+ const set = sets . get ( id ) ;
120+ expect ( set ) . to . have . length ( 3 ) ;
121+ } ) ;
122+ } ) ;
123+
124+ test ( 'recursively create all sets with bot responses' , ( ) => {
125+ const mapResponses = getMapResponses (
126+ buildMockResponses ( mockItem , mockMembers ) ,
127+ ) ;
128+ const mapBotResponses = getMapResponses (
129+ buildMockBotResponses ( mockItem , mockMembers ) ,
130+ ) ;
131+ const participantIterator = mockMembers . entries ( ) ;
132+ const sets = recursivelyCreateAllPartiallyBlindSets (
133+ participantIterator ,
134+ mapResponses ,
135+ mapBotResponses ,
136+ 2 ,
97137 1 ,
98138 ) ;
99139 expect ( sets . size ) . not . toBe ( 0 ) ;
100140 expect ( sets ) . to . have . keys ( mockMembers . map ( ( { id } ) => id ) ) ;
141+ mockMembers . forEach ( ( { id } ) => {
142+ const set = sets . get ( id ) ;
143+ expect ( set ) . to . have . length ( 3 ) ;
144+ } ) ;
101145} ) ;
102146
103147test ( 'filtering bot responses' , ( ) => {
104- const responsesMap = getMapResponses ( ) ;
148+ const responsesMap = getMapResponses (
149+ buildMockResponses ( mockItem , mockMembers ) ,
150+ ) ;
105151 const responses = Array . from ( responsesMap . values ( ) ) ;
106152
107153 expect ( responses . length ) . toBeGreaterThanOrEqual ( 3 ) ;
0 commit comments