From 702f59a90e1e18941b03daa750fc8520e83041b4 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 19 Jun 2023 15:36:19 +0100 Subject: [PATCH] Improve tests --- .../postgres.integration.spec.ts | 117 +++++++++++++++++- 1 file changed, 112 insertions(+), 5 deletions(-) diff --git a/qa-core/src/integrations/external-schema/postgres.integration.spec.ts b/qa-core/src/integrations/external-schema/postgres.integration.spec.ts index e8264c99cb..2ac812ad70 100644 --- a/qa-core/src/integrations/external-schema/postgres.integration.spec.ts +++ b/qa-core/src/integrations/external-schema/postgres.integration.spec.ts @@ -63,12 +63,18 @@ describe("getExternalSchema", () => { it("can export a database with tables", async () => { const integration = new postgres.integration(config) - integration.internalQuery({ + await integration.internalQuery({ sql: ` - CREATE TABLE IF NOT EXISTS "users" ( + CREATE TABLE "users" ( + "id" SERIAL, + "name" VARCHAR(100) NOT NULL, + "role" VARCHAR(15) NOT NULL, + PRIMARY KEY ("id") + ); + CREATE TABLE "products" ( "id" SERIAL, "name" VARCHAR(100) NOT NULL, - "role" VARCHAR(15) NOT NULL, + "price" DECIMAL NOT NULL, PRIMARY KEY ("id") );`, }) @@ -97,6 +103,41 @@ describe("getExternalSchema", () => { SET default_table_access_method = heap; + -- + -- Name: products; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.products ( + id integer NOT NULL, + name character varying(100) NOT NULL, + price numeric NOT NULL + ); + + + ALTER TABLE public.products OWNER TO postgres; + + -- + -- Name: products_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres + -- + + CREATE SEQUENCE public.products_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + + ALTER TABLE public.products_id_seq OWNER TO postgres; + + -- + -- Name: products_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres + -- + + ALTER SEQUENCE public.products_id_seq OWNED BY public.products.id; + + -- -- Name: users; Type: TABLE; Schema: public; Owner: postgres -- @@ -132,6 +173,13 @@ describe("getExternalSchema", () => { ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id; + -- + -- Name: products id; Type: DEFAULT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.products ALTER COLUMN id SET DEFAULT nextval('public.products_id_seq'::regclass); + + -- -- Name: users id; Type: DEFAULT; Schema: public; Owner: postgres -- @@ -139,6 +187,14 @@ describe("getExternalSchema", () => { ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass); + -- + -- Name: products products_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.products + ADD CONSTRAINT products_pkey PRIMARY KEY (id); + + -- -- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres -- @@ -158,8 +214,9 @@ describe("getExternalSchema", () => { it("does not export a data", async () => { const integration = new postgres.integration(config) - integration.internalQuery({ - sql: `INSERT INTO "users" ("name", "role") VALUES ('John Doe', 'Administrator');`, + await integration.internalQuery({ + sql: `INSERT INTO "users" ("name", "role") VALUES ('John Doe', 'Administrator'); + INSERT INTO "products" ("name", "price") VALUES ('Book', 7.68);`, }) const result = await integration.getExternalSchema() @@ -186,6 +243,41 @@ describe("getExternalSchema", () => { SET default_table_access_method = heap; + -- + -- Name: products; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.products ( + id integer NOT NULL, + name character varying(100) NOT NULL, + price numeric NOT NULL + ); + + + ALTER TABLE public.products OWNER TO postgres; + + -- + -- Name: products_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres + -- + + CREATE SEQUENCE public.products_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + + ALTER TABLE public.products_id_seq OWNER TO postgres; + + -- + -- Name: products_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres + -- + + ALTER SEQUENCE public.products_id_seq OWNED BY public.products.id; + + -- -- Name: users; Type: TABLE; Schema: public; Owner: postgres -- @@ -221,6 +313,13 @@ describe("getExternalSchema", () => { ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id; + -- + -- Name: products id; Type: DEFAULT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.products ALTER COLUMN id SET DEFAULT nextval('public.products_id_seq'::regclass); + + -- -- Name: users id; Type: DEFAULT; Schema: public; Owner: postgres -- @@ -228,6 +327,14 @@ describe("getExternalSchema", () => { ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass); + -- + -- Name: products products_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.products + ADD CONSTRAINT products_pkey PRIMARY KEY (id); + + -- -- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --