Skip to content

Commit

Permalink
test: pg string adapter sets model field correctly from a schema with…
Browse files Browse the repository at this point in the history
… a SERIAL field
  • Loading branch information
p5quared committed Oct 14, 2024
1 parent 102c544 commit 09e08e8
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ type Story @refersTo(name: \\"stories\\") @model {
"
`;

exports[`generate graphqlSchemaFromSQLSchema creates graphql schema from "postgres" "serial" schema 1`] = `
"input AMPLIFY {
engine: String = \\"postgres\\"
}
type SerialTable @refersTo(name: \\" serial_table\\") @model {
id: Int! @primaryKey
number: Int
}
"
`;

exports[`generate graphqlSchemaFromSQLSchema creates graphql schema from "postgres" "todo" schema 1`] = `
"input AMPLIFY {
engine: String = \\"postgres\\"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,38 @@ Array [
},
]
`;

exports[`testPostgresStringDataSourceAdapter sets the model field correctly from a schema with a SERIAL field 1`] = `
Array [
Object {
"default": Object {
"kind": "DB_GENERATED",
"value": "nextval('serial_table_id_seq'::regclass)",
},
"length": "",
"name": "id",
"type": Object {
"kind": "NonNull",
"type": Object {
"kind": "Scalar",
"name": "Int",
},
},
},
Object {
"default": Object {
"kind": "DB_GENERATED",
"value": "nextval('serial_table_number_seq'::regclass)",
},
"length": "",
"name": "number",
"type": Object {
"kind": "NonNull",
"type": Object {
"kind": "Scalar",
"name": "Int",
},
},
},
]
`;
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,16 @@ comments,comment_text,NULL,4,varchar,varchar(30),NO,30,NULL,NULL,NULL,NULL`,
"stories",NULL,NULL,"placeholder",NULL,3,"character","bpchar","NO",1,NULL,NULL,NULL
"stories",NULL,NULL,"pub_id",NULL,1,"integer","int4","NO",NULL,"stories_pkey","PRIMARY KEY","pub_id, pub_type"
"stories",NULL,NULL,"pub_type","'S'::bpchar",2,"character","bpchar","NO",1,"stories_pkey","PRIMARY KEY","pub_id, pub_type"`,
/*
* CREATE TABLE serial_table (
* id SERIAL PRIMARY KEY,
* number SERIAL,
* );
*/
serial: `
"table_name","enum_name","enum_values","column_name","column_default","ordinal_position","data_type","udt_name","is_nullable","character_maximum_length","indexname","constraint_type","index_columns"
serial_table,,,id,nextval('serial_table_id_seq'::regclass),1,integer,int4,NO,,serial_table_pkey,PRIMARY KEY,id
serial_table,,,number,nextval('serial_table_number_seq'::regclass),2,integer,int4,NO,,,,
`,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ describe('testPostgresStringDataSourceAdapter', () => {
expect(adapter.getModels()).toMatchSnapshot();
});

it('sets the model field correctly from a schema with a SERIAL field', () => {
/*
* CREATE TABLE serial_table (
* id SERIAL PRIMARY KEY,
* number SERIAL,
* );
*/
const adapter = new PostgresStringDataSourceAdapter(schemas.postgres.serial);
expect(adapter.getModels()[0].getFields()).toMatchSnapshot();
});

it('sets the correct models from a news schema', () => {
const adapter = new PostgresStringDataSourceAdapter(schemas.postgres.news);
expect(adapter.getModels()).toMatchSnapshot();
Expand Down

0 comments on commit 09e08e8

Please sign in to comment.