11import { describe , expect , test } from 'vitest'
22import { z } from 'zod'
3- import { generateCollectionTableDefinition , defineCollection } from '../../src/utils/collection'
3+ import { generateCollectionTableDefinition , defineCollection , resolveCollection } from '../../src/utils/collection'
44import { getTableName } from '../utils/database'
55
66describe ( 'generateCollectionTableDefinition' , ( ) => {
77 test ( 'Page without custom schema' , ( ) => {
8- const collection = defineCollection ( {
8+ const collection = resolveCollection ( 'content' , defineCollection ( {
99 type : 'page' ,
1010 source : 'pages/**' ,
11- } )
12- const sql = generateCollectionTableDefinition ( 'content' , collection )
11+ } ) ) !
12+ const sql = generateCollectionTableDefinition ( collection )
1313
1414 expect ( sql ) . toBe ( [
1515 `CREATE TABLE IF NOT EXISTS ${ getTableName ( 'content' ) } (` ,
@@ -28,14 +28,14 @@ describe('generateCollectionTableDefinition', () => {
2828 } )
2929
3030 test ( 'Page with custom schema' , ( ) => {
31- const collection = defineCollection ( {
31+ const collection = resolveCollection ( 'content' , defineCollection ( {
3232 type : 'page' ,
3333 source : 'pages/**' ,
3434 schema : z . object ( {
3535 customField : z . string ( ) ,
3636 } ) ,
37- } )
38- const sql = generateCollectionTableDefinition ( 'content' , collection )
37+ } ) ) !
38+ const sql = generateCollectionTableDefinition ( collection )
3939
4040 expect ( sql ) . toBe ( [
4141 `CREATE TABLE IF NOT EXISTS ${ getTableName ( 'content' ) } (` ,
@@ -55,14 +55,14 @@ describe('generateCollectionTableDefinition', () => {
5555 } )
5656
5757 test ( 'Data with schema' , ( ) => {
58- const collection = defineCollection ( {
58+ const collection = resolveCollection ( 'content' , defineCollection ( {
5959 type : 'data' ,
6060 source : 'data/**' ,
6161 schema : z . object ( {
6262 customField : z . string ( ) ,
6363 } ) ,
64- } )
65- const sql = generateCollectionTableDefinition ( 'content' , collection )
64+ } ) ) !
65+ const sql = generateCollectionTableDefinition ( collection )
6666
6767 expect ( sql ) . toBe ( [
6868 `CREATE TABLE IF NOT EXISTS ${ getTableName ( 'content' ) } (` ,
@@ -77,14 +77,14 @@ describe('generateCollectionTableDefinition', () => {
7777
7878 // Columns
7979 test ( 'String with max length' , ( ) => {
80- const collection = defineCollection ( {
80+ const collection = resolveCollection ( 'content' , defineCollection ( {
8181 type : 'data' ,
8282 source : 'data/**' ,
8383 schema : z . object ( {
8484 customField : z . string ( ) . max ( 64 ) . default ( 'foo' ) ,
8585 } ) ,
86- } )
87- const sql = generateCollectionTableDefinition ( 'content' , collection )
86+ } ) ) !
87+ const sql = generateCollectionTableDefinition ( collection )
8888
8989 expect ( sql ) . toBe ( [
9090 `CREATE TABLE IF NOT EXISTS ${ getTableName ( 'content' ) } (` ,
@@ -98,14 +98,14 @@ describe('generateCollectionTableDefinition', () => {
9898 } )
9999
100100 test ( 'Number' , ( ) => {
101- const collection = defineCollection ( {
101+ const collection = resolveCollection ( 'content' , defineCollection ( {
102102 type : 'data' ,
103103 source : 'data/**' ,
104104 schema : z . object ( {
105105 customField : z . number ( ) . default ( 13 ) ,
106106 } ) ,
107- } )
108- const sql = generateCollectionTableDefinition ( 'content' , collection )
107+ } ) ) !
108+ const sql = generateCollectionTableDefinition ( collection )
109109
110110 expect ( sql ) . toBe ( [
111111 `CREATE TABLE IF NOT EXISTS ${ getTableName ( 'content' ) } (` ,
@@ -119,14 +119,14 @@ describe('generateCollectionTableDefinition', () => {
119119 } )
120120
121121 test ( 'Boolean' , ( ) => {
122- const collection = defineCollection ( {
122+ const collection = resolveCollection ( 'content' , defineCollection ( {
123123 type : 'data' ,
124124 source : 'data/**' ,
125125 schema : z . object ( {
126126 customField : z . boolean ( ) . default ( false ) ,
127127 } ) ,
128- } )
129- const sql = generateCollectionTableDefinition ( 'content' , collection )
128+ } ) ) !
129+ const sql = generateCollectionTableDefinition ( collection )
130130
131131 expect ( sql ) . toBe ( [
132132 `CREATE TABLE IF NOT EXISTS ${ getTableName ( 'content' ) } (` ,
@@ -140,14 +140,14 @@ describe('generateCollectionTableDefinition', () => {
140140 } )
141141
142142 test ( 'Date' , ( ) => {
143- const collection = defineCollection ( {
143+ const collection = resolveCollection ( 'content' , defineCollection ( {
144144 type : 'data' ,
145145 source : 'data/**' ,
146146 schema : z . object ( {
147147 customField : z . date ( ) ,
148148 } ) ,
149- } )
150- const sql = generateCollectionTableDefinition ( 'content' , collection )
149+ } ) ) !
150+ const sql = generateCollectionTableDefinition ( collection )
151151
152152 expect ( sql ) . toBe ( [
153153 `CREATE TABLE IF NOT EXISTS ${ getTableName ( 'content' ) } (` ,
@@ -161,7 +161,7 @@ describe('generateCollectionTableDefinition', () => {
161161 } )
162162
163163 test ( 'Object' , ( ) => {
164- const collection = defineCollection ( {
164+ const collection = resolveCollection ( 'content' , defineCollection ( {
165165 type : 'data' ,
166166 source : 'data/**' ,
167167 schema : z . object ( {
@@ -170,8 +170,8 @@ describe('generateCollectionTableDefinition', () => {
170170 f2 : z . string ( ) ,
171171 } ) ,
172172 } ) ,
173- } )
174- const sql = generateCollectionTableDefinition ( 'content' , collection )
173+ } ) ) !
174+ const sql = generateCollectionTableDefinition ( collection )
175175
176176 expect ( sql ) . toBe ( [
177177 `CREATE TABLE IF NOT EXISTS ${ getTableName ( 'content' ) } (` ,
@@ -185,7 +185,7 @@ describe('generateCollectionTableDefinition', () => {
185185 } )
186186
187187 test ( 'Array' , ( ) => {
188- const collection = defineCollection ( {
188+ const collection = resolveCollection ( 'content' , defineCollection ( {
189189 type : 'data' ,
190190 source : 'data/**' ,
191191 schema : z . object ( {
@@ -194,8 +194,8 @@ describe('generateCollectionTableDefinition', () => {
194194 f2 : z . string ( ) ,
195195 } ) ) ,
196196 } ) ,
197- } )
198- const sql = generateCollectionTableDefinition ( 'content' , collection )
197+ } ) ) !
198+ const sql = generateCollectionTableDefinition ( collection )
199199
200200 expect ( sql ) . toBe ( [
201201 `CREATE TABLE IF NOT EXISTS ${ getTableName ( 'content' ) } (` ,
@@ -209,7 +209,7 @@ describe('generateCollectionTableDefinition', () => {
209209 } )
210210
211211 test ( 'Nullable' , ( ) => {
212- const collection = defineCollection ( {
212+ const collection = resolveCollection ( 'content' , defineCollection ( {
213213 type : 'data' ,
214214 source : 'data/**' ,
215215 schema : z . object ( {
@@ -225,8 +225,8 @@ describe('generateCollectionTableDefinition', () => {
225225 } ) . nullable ( ) ,
226226 f6 : z . array ( z . any ( ) ) . nullable ( ) ,
227227 } ) ,
228- } )
229- const sql = generateCollectionTableDefinition ( 'content' , collection )
228+ } ) ) !
229+ const sql = generateCollectionTableDefinition ( collection )
230230
231231 expect ( sql ) . toBe ( [
232232 `CREATE TABLE IF NOT EXISTS ${ getTableName ( 'content' ) } (` ,
0 commit comments