-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
6 changed files
with
39 additions
and
234 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,76 +1,41 @@ | ||
import { ColumnForDataTableFragment } from "@gen/graphql-types"; | ||
import { sampleQuery } from "./utils"; | ||
|
||
const idPKColumn: ColumnForDataTableFragment = { | ||
name: "id", | ||
isPrimaryKey: true, | ||
type: "INT", | ||
}; | ||
|
||
const pkPKColumn: ColumnForDataTableFragment = { | ||
name: "pk2", | ||
isPrimaryKey: true, | ||
type: "INT", | ||
}; | ||
|
||
const nameColumn: ColumnForDataTableFragment = { | ||
name: "name", | ||
isPrimaryKey: false, | ||
type: "VARCHAR(16383)", | ||
}; | ||
|
||
describe("tests sampleQuery", () => { | ||
const tests: Array<{ | ||
desc: string; | ||
cols: ColumnForDataTableFragment[]; | ||
expectedQuery: string; | ||
expectedShowLink: boolean; | ||
tableName?: string; | ||
}> = [ | ||
{ | ||
desc: "Keyless table", | ||
cols: [nameColumn], | ||
expectedQuery: `SELECT *\nFROM \`Keyless table\`\nLIMIT 200;\n`, | ||
expectedShowLink: false, | ||
expectedQuery: `SELECT * FROM \`Keyless table\``, | ||
tableName: "Keyless table", | ||
}, | ||
{ | ||
desc: "One key and data", | ||
cols: [idPKColumn, nameColumn], | ||
expectedQuery: `SELECT *\nFROM \`One key and data table\`\nORDER BY \`id\` ASC\nLIMIT 200;\n`, | ||
expectedShowLink: true, | ||
expectedQuery: `SELECT * FROM \`One key and data table\``, | ||
tableName: "One key and data table", | ||
}, | ||
{ | ||
desc: "Two Key", | ||
cols: [idPKColumn, pkPKColumn], | ||
expectedQuery: `SELECT *\nFROM \`Two Keys table\`\nORDER BY \`id\` ASC, \`pk2\` ASC\nLIMIT 200;\n`, | ||
expectedShowLink: true, | ||
expectedQuery: `SELECT * FROM \`Two Keys table\``, | ||
tableName: "Two Keys table", | ||
}, | ||
{ | ||
desc: "Two Keys and data", | ||
cols: [idPKColumn, pkPKColumn, nameColumn], | ||
expectedQuery: `SELECT *\nFROM \`Two Keys and data table\`\nORDER BY \`id\` ASC, \`pk2\` ASC\nLIMIT 200;\n`, | ||
expectedShowLink: true, | ||
expectedQuery: `SELECT * FROM \`Two Keys and data table\``, | ||
tableName: "Two Keys and data table", | ||
}, | ||
{ | ||
desc: "no table Name", | ||
cols: [idPKColumn, pkPKColumn, nameColumn], | ||
expectedShowLink: false, | ||
expectedQuery: `SHOW TABLES;\n`, | ||
}, | ||
]; | ||
|
||
tests.forEach(test => { | ||
it(`tests ${test.desc} table default query`, () => { | ||
const { sqlQuery, showDefaultQueryInfo } = sampleQuery( | ||
test.tableName, | ||
test.cols, | ||
); | ||
const sqlQuery = sampleQuery(test.tableName); | ||
expect(sqlQuery).toContain(test.expectedQuery); | ||
expect(showDefaultQueryInfo).toBe(test.expectedShowLink); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.