Skip to content

Commit

Permalink
correct TableClass and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcellino-Palerme committed Jan 12, 2024
1 parent 05c1356 commit 2020f09
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion server/api/class/tableClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class Table {

if (resp.rows.length == 0){
client.end();
throw new Error(`Table ${nameTable} doesn't exist`);
throw new Error(`${nameTable} table doesn't exist`);
}

for(const row of resp.rows as {column_name:string, data_type:string}[]){
Expand Down
4 changes: 3 additions & 1 deletion test/db/compound.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ describe("Compound table", async ()=>{
{columnName:"id", type:"integer", maxLength:null},
{columnName:"name", type:"character varying", maxLength:255},
{columnName:"url", type:"character varying", maxLength:255},
{columnName:"description", type:"text", maxLength:null}
{columnName:"description", type:"text", maxLength:null},
{columnName:"archive_date", type:"timestamp with time zone",
maxLength:null},
];

const client = new pg.Client();
Expand Down
19 changes: 7 additions & 12 deletions test/server/tableClass.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,26 @@ describe("tableClass", async ()=>{
});

test("bad name table",async ()=>{
expect(await(new Table("unknow"))).toThrowError("unknow table does't exist");
expect(await(new Table("unknow"))).toThrowError(/^unknow table doesn't exist$/);
});

// Define structure of compound table
const compound:{columnName:string, type:string, maxLength:number|null}[] = [
{columnName:"id", type:"integer", maxLength:null},
{columnName:"name", type:"character varying", maxLength:255},
{columnName:"url", type:"character varying", maxLength:255},
{columnName:"description", type:"text", maxLength:null}
{columnName:"description", type:"text", maxLength:null},
{columnName:"archive_date", type:"timestamp with time zone",
maxLength:null},
];
const compTable = new Table("compound");
const compTable = await (new Table("compound"));
const compHeader = compTable.header;

test("Check number of header", ()=>{
test("Check number of header without id", ()=>{
expect(compHeader.length).toBe(compound.length - 1);
});

// const columnNames = resp.rows.map((x:{column_name:string}) =>
// x.column_name);

// test("Check name of column", () =>{
// // thx : https://stackoverflow.com/a/77081601
// expect(new Set(columnNames)).toEqual(
// new Set(compound.map(x => x.columnName)));
// });

test("getHearder", () => {

});
Expand Down

0 comments on commit 2020f09

Please sign in to comment.