1- import { describe , it , expect } from "vitest" ;
2- import { processCollectionToSection } from "../../src/utils/processCollectionToSection.js" ;
1+ import { Selectable } from "kysely" ;
32import { sepolia } from "viem/chains" ;
4- import { Database as DataDatabase } from "../../src/types/supabaseData.js" ;
3+ import { describe , expect , it } from "vitest" ;
4+ import { DataDatabase } from "../../src/types/kyselySupabaseData.js" ;
5+ import { processCollectionToSection } from "../../src/utils/processCollectionToSection.js" ;
56
67describe ( "processCollectionToSection" , async ( ) => {
78 const collection = {
@@ -22,7 +23,7 @@ describe("processCollectionToSection", async () => {
2223 hyperboardHypercertMetadata : [ ] ,
2324 collection,
2425 } ;
25- const user1 : DataDatabase [ "public" ] [ "Tables" ] [ " users"] [ "Row" ] = {
26+ const user1 : Selectable < DataDatabase [ "users" ] > = {
2627 address : "0x1" ,
2728 chain_id : sepolia . id ,
2829 avatar : "testAvatar1" ,
@@ -31,7 +32,7 @@ describe("processCollectionToSection", async () => {
3132 created_at : new Date ( ) . toISOString ( ) ,
3233 } ;
3334
34- const user2 : DataDatabase [ "public" ] [ "Tables" ] [ " users"] [ "Row" ] = {
35+ const user2 : Selectable < DataDatabase [ "users" ] > = {
3536 address : "0x2" ,
3637 chain_id : sepolia . id ,
3738 avatar : "testAvatar2" ,
@@ -111,31 +112,33 @@ describe("processCollectionToSection", async () => {
111112 hypercert_allow_lists_id : "test" ,
112113 } ;
113114
114- const hypercertMetadata1 : DataDatabase [ "public" ] [ "Tables" ] [ "hyperboard_hypercert_metadata" ] [ "Row" ] =
115- {
116- hypercert_id : hypercert1 . hypercert_id as string ,
117- hyperboard_id : "testHyperboard1" ,
118- collection_id : "testCollection1" ,
119- display_size : 1 ,
120- created_at : new Date ( ) . toISOString ( ) ,
121- } ;
115+ const hypercertMetadata1 : Selectable <
116+ DataDatabase [ "hyperboard_hypercert_metadata" ]
117+ > = {
118+ hypercert_id : hypercert1 . hypercert_id as string ,
119+ hyperboard_id : "testHyperboard1" ,
120+ collection_id : "testCollection1" ,
121+ display_size : 1 ,
122+ created_at : new Date ( ) . toISOString ( ) ,
123+ } ;
122124
123- const hypercertMetadata2 : DataDatabase [ "public" ] [ "Tables" ] [ "hyperboard_hypercert_metadata" ] [ "Row" ] =
124- {
125- hypercert_id : hypercert2 . hypercert_id as string ,
126- hyperboard_id : "testHyperboard2" ,
127- collection_id : "testCollection2" ,
128- display_size : 1 ,
129- created_at : new Date ( ) . toISOString ( ) ,
130- } ;
125+ const hypercertMetadata2 : Selectable <
126+ DataDatabase [ "hyperboard_hypercert_metadata" ]
127+ > = {
128+ hypercert_id : hypercert2 . hypercert_id as string ,
129+ hyperboard_id : "testHyperboard2" ,
130+ collection_id : "testCollection2" ,
131+ display_size : 1 ,
132+ created_at : new Date ( ) . toISOString ( ) ,
133+ } ;
131134 it ( "should process empty collection to section" , async ( ) => {
132135 const emptySection = processCollectionToSection ( emptyArgs ) ;
133136
134137 expect ( emptySection ) . toBeDefined ( ) ;
135138 expect ( emptySection . entries ) . toBeDefined ( ) ;
136- expect ( emptySection . entries . length ) . toBe ( 0 ) ;
139+ expect ( emptySection . entries ? .length ) . toBe ( 0 ) ;
137140 expect ( emptySection . owners ) . toBeDefined ( ) ;
138- expect ( emptySection . owners . length ) . toBe ( 0 ) ;
141+ expect ( emptySection . owners ?. data ? .length ) . toBe ( 0 ) ;
139142 } ) ;
140143
141144 it ( "should process allowlist entries according to size" , async ( ) => {
@@ -148,14 +151,14 @@ describe("processCollectionToSection", async () => {
148151 allowlistEntries : [ allowlistEntry1 , allowlistEntry2 ] ,
149152 } ) ;
150153
151- expect ( section . owners . length ) . toBe ( 2 ) ;
154+ expect ( section . owners ?. data ? .length ) . toBe ( 2 ) ;
152155 expect (
153- section . owners . find (
156+ section . owners ?. data ? .find (
154157 ( owner ) => owner . address === allowlistEntry1 . user_address ,
155158 ) ?. percentage_owned ,
156159 ) . toBe ( 25 ) ;
157160 expect (
158- section . owners . find (
161+ section . owners ?. data ? .find (
159162 ( owner ) => owner . address === allowlistEntry2 . user_address ,
160163 ) ?. percentage_owned ,
161164 ) . toBe ( 75 ) ;
@@ -172,8 +175,8 @@ describe("processCollectionToSection", async () => {
172175 ] ,
173176 } ) ;
174177
175- expect ( section . owners . length ) . toBe ( 1 ) ;
176- expect ( section . owners [ 0 ] . percentage_owned ) . toBe ( 100 ) ;
178+ expect ( section . owners ?. data ? .length ) . toBe ( 1 ) ;
179+ expect ( section . owners ?. data ?. [ 0 ] . percentage_owned ) . toBe ( 100 ) ;
177180 } ) ;
178181
179182 it ( "should use correct user metadata for allowlist entries" , async ( ) => {
@@ -186,17 +189,21 @@ describe("processCollectionToSection", async () => {
186189 } ) ;
187190 console . log ( owners ) ;
188191 expect (
189- owners . find ( ( owner ) => owner . address === user1 . address ) ?. avatar ,
192+ owners ?. data ? .find ( ( owner ) => owner . address === user1 . address ) ?. avatar ,
190193 ) . toBe ( user1 . avatar ) ;
191194 expect (
192- owners . find ( ( owner ) => owner . address === user1 . address ) ?. display_name ,
195+ owners ?. data ?. find ( ( owner ) => owner . address === user1 . address )
196+ ?. display_name ,
193197 ) . toBe ( user1 . display_name ) ;
194198 } ) ;
195199
196200 it ( "Should adjust for display size" , ( ) => {
197201 const { owners } = processCollectionToSection ( {
198202 ...emptyArgs ,
199- hypercerts : [ hypercert1 , { ...hypercert2 , units : 157 } ] ,
203+ hypercerts : [
204+ { ...hypercert1 , units : 100 } ,
205+ { ...hypercert2 , units : 100 } ,
206+ ] ,
200207 hyperboardHypercertMetadata : [ hypercertMetadata1 , hypercertMetadata2 ] ,
201208 users : [ user1 , user2 ] ,
202209 fractions : [
@@ -205,7 +212,7 @@ describe("processCollectionToSection", async () => {
205212 hypercert_id : hypercert1 . hypercert_id ,
206213 owner_address : user1 . address ,
207214 token_id : 1 ,
208- units : 1 ,
215+ units : 100 ,
209216 creation_block_timestamp : 1 ,
210217 creation_block_number : 1 ,
211218 last_update_block_number : 1 ,
@@ -219,7 +226,7 @@ describe("processCollectionToSection", async () => {
219226 hypercert_id : hypercert2 . hypercert_id ,
220227 owner_address : user2 . address ,
221228 token_id : 2 ,
222- units : 157 ,
229+ units : 100 ,
223230 creation_block_timestamp : 1 ,
224231 creation_block_number : 1 ,
225232 last_update_block_number : 1 ,
@@ -231,6 +238,10 @@ describe("processCollectionToSection", async () => {
231238 ] ,
232239 } ) ;
233240
234- expect ( owners [ 0 ] . percentage_owned ) . toBe ( owners [ 1 ] . percentage_owned ) ;
241+ expect ( owners ?. data ?. [ 0 ] . percentage_owned ) . toBe ( 50 ) ;
242+ expect ( owners ?. data ?. [ 1 ] . percentage_owned ) . toBe ( 50 ) ;
243+ expect ( owners ?. data ?. [ 0 ] . percentage_owned ) . toBe (
244+ owners ?. data ?. [ 1 ] . percentage_owned ,
245+ ) ;
235246 } ) ;
236247} ) ;
0 commit comments