-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
DominicGBauer
committed
Sep 9, 2024
1 parent
a8bb3d9
commit f7fb98a
Showing
7 changed files
with
676 additions
and
236 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
tools/diagnostics-app/tests/library/powersync/JsSchemaGenerator.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { JsSchemaGenerator } from '../../../src/library/powersync/JsSchemaGenerator' | ||
import { Schema, Table, Column, ColumnType, column } from '@powersync/web'; | ||
|
||
describe('JsSchemaGenerator', () => { | ||
const generator = new JsSchemaGenerator(); | ||
|
||
describe('generate', () => { | ||
it('should generate a schema with multiple tables', () => { | ||
const users = new Table({ | ||
id: column.text, | ||
name: column.text, | ||
}) | ||
const posts = new Table({ | ||
id: column.text, | ||
title: column.text, | ||
content: column.text | ||
}) | ||
const schema = new Schema({ users, posts }); | ||
|
||
const result = generator.generate(schema); | ||
|
||
expect(result).toBe( | ||
`new Schema({ | ||
new Table({ | ||
id: column.text, | ||
name: column.text | ||
}), | ||
new Table({ | ||
id: column.text, | ||
title: column.text, | ||
content: column.text | ||
}) | ||
}) | ||
` | ||
); | ||
}); | ||
}); | ||
|
||
describe('generateTable', () => { | ||
it('should generate a table with columns', () => { | ||
const columns = [ | ||
new Column({ name: 'id', type: ColumnType.TEXT }), | ||
new Column({ name: 'age', type: ColumnType.INTEGER }), | ||
]; | ||
|
||
const result = (generator as any).generateTable('users', columns); | ||
|
||
expect(result).toBe( | ||
`new Table({ | ||
id: column.text, | ||
age: column.integer | ||
})` | ||
); | ||
}); | ||
}); | ||
|
||
describe('generateColumn', () => { | ||
it('should generate a column', () => { | ||
const column = new Column({ name: 'email', type: ColumnType.TEXT }); | ||
|
||
const result = (generator as any).generateColumn(column); | ||
|
||
expect(result).toBe('email: column.text'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "./", | ||
"esModuleInterop": true, | ||
"jsx": "react", | ||
"rootDir": "../", | ||
"composite": true, | ||
"outDir": "./lib", | ||
"lib": ["esnext", "DOM"], | ||
"module": "esnext", | ||
"sourceMap": true, | ||
"moduleResolution": "node", | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"noImplicitUseStrict": false, | ||
"noStrictGenericChecks": false, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"target": "esnext" | ||
}, | ||
"include": ["../src/**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
test: {}, | ||
}) |