Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reset_database #323

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions frontend/e2e/database/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pg from "pg"

export default class DB {
private DBConfig = {
user: "test",
host: "localhost",
database: "risnorms",
password: "test",
port: 5432,
max: 10,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
allowExitOnIdle: false,
}

private pool: pg.Pool = new pg.Pool(this.DBConfig)

async getDBConnection(): Promise<pg.PoolClient> {
if (!this.pool) {
this.pool = new pg.Pool(this.DBConfig)
const client = await this.pool.connect()
console.log(`---------> √ DB connection has been established! <---------`)
return client
} else {
return this.pool.connect()
}
}

async executeQuery(query: string): Promise<void> {
try {
const client: pg.PoolClient = await this.getDBConnection()
const result: pg.QueryResult = await client.query(query)
console.log(result.rows)
} catch (error) {
console.error("Error executing query:", error)
}
}
}
23 changes: 23 additions & 0 deletions frontend/e2e/database/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import DB from "./db"
import * as fs from "node:fs"

const connectToDB = new DB()

async function establishDBConnection() {
try {
await connectToDB.getDBConnection()
} catch (error) {
console.log(
`---------> X Failed to connect to dataBase <--------- \n\n ${error}`,
)
process.exit(1)
}
}

async function globalSetup() {
await establishDBConnection()
const sql = fs.readFileSync("e2e/database/initial_data.sql").toString()
await connectToDB.executeQuery(sql)
}

export default globalSetup
14,336 changes: 14,336 additions & 0 deletions frontend/e2e/database/initial_data.sql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { test, expect, Page } from "@playwright/test"
import { readFileSync } from "fs"
import globalSetup from "@e2e/database/globalSetup"

test.describe("Publishing flow for an amending law", () => {
async function verifyPublicationTime(
Expand Down Expand Up @@ -32,6 +33,7 @@ test.describe("Publishing flow for an amending law", () => {
}

test("navigate to publishing page for an amending law", async ({ page }) => {
await globalSetup()
await page.goto(
"/amending-laws/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/publishing",
)
Expand Down
145 changes: 128 additions & 17 deletions frontend/e2e/navigate-to-temporal-data-page-and-test-content.spec.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,145 @@
import { test, expect } from "@playwright/test"
import globalSetup from "@e2e/database/globalSetup"

test("navigate to temporal data page for an amending law", async ({ page }) => {
await page.goto(
"/amending-laws/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/temporal-data",
)
await expect(
page.locator('[data-testid="temporalDataHeading"]'),
).toBeVisible()
})

test.describe("Temporal Data for an amending law", () => {
const BASE_URL =
"/amending-laws/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/temporal-data"

test.describe("Navigate to temporal data page and test its rendered content", () => {
test.beforeEach(async ({ page }) => {
await page.goto(BASE_URL)
await globalSetup()
await page.goto(
"/amending-laws/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/temporal-data",
)
})

test("navigate to temporal data page for an amending law", async ({
page,
}) => {
await expect(
page.locator('[data-testid="temporalDataHeading"]'),
).toBeVisible()
})

test(`contents of entry into force article html rendering`, async ({
page,
}) => {
await expect(page.getByText("Artikel 3Inkrafttreten")).toBeVisible()
})
})

test.describe("management of Temporal Data for an amending law", () => {
test(`renders correct number of date inputs for the time boundaries`, async ({
page,
}) => {
const dateInput = page.locator('[data-testid="date-input-field"]')
await expect(dateInput).toHaveCount(1)
const inputValue = await dateInput.inputValue()
await page.goto(
"/amending-laws/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/temporal-data",
)
const saveButton = page.locator("text=Speichern")
let dateInputs = page.locator('[data-testid="date-input-field"]')

await expect(dateInputs).toHaveCount(1)
const inputValue = await dateInputs.inputValue()
await expect(inputValue).toBe("16.03.2017")

// add new time boundaries
const newDateInput = page.locator('[data-testid="new-date-input-field"]')
await newDateInput.fill("01-05-2023")
await newDateInput.fill("02-06-2023")
await saveButton.click()

await page.waitForResponse(
(response) =>
response.url().includes("timeBoundaries") && response.status() === 200,
)

const addTimeBoundariesResponse = await page.request.get(
`/api/v1/norms/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/timeBoundaries`,
{
headers: {
Accept: "application/json",
},
},
)

const addedTimeBoundaries = await addTimeBoundariesResponse.json()

expect(addedTimeBoundaries).toEqual([
{ date: "2017-03-16", eventRefEid: "meta-1_lebzykl-1_ereignis-2" },
{ date: "2023-05-01", eventRefEid: "meta-1_lebzykl-1_ereignis-3" },
{ date: "2023-06-02", eventRefEid: "meta-1_lebzykl-1_ereignis-4" },
])

//edit time boundaries

await expect(dateInputs).toHaveCount(3)
const dateInputToEdit = page
.locator('[data-testid="date-input-field"]')
.nth(1)
await dateInputToEdit.fill("")
await dateInputToEdit.fill("03.06.2023")
await saveButton.click()

await page.waitForResponse(
(response) =>
response.url().includes("timeBoundaries") && response.status() === 200,
)

const editedTimeboundariesResponse = await page.request.get(
`/api/v1/norms/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/timeBoundaries`,
{
headers: {
Accept: "application/json",
},
},
)
const editedTimeboundaries = await editedTimeboundariesResponse.json()

expect(editedTimeboundaries).toEqual([
{ date: "2017-03-16", eventRefEid: "meta-1_lebzykl-1_ereignis-2" },
{ date: "2023-06-03", eventRefEid: "meta-1_lebzykl-1_ereignis-3" },
{ date: "2023-06-02", eventRefEid: "meta-1_lebzykl-1_ereignis-4" },
])

const editedValue = await dateInputs.nth(1).inputValue()
await expect(editedValue).toBe("03.06.2023")

// delete time boundaries

for (let i = 2; i > 0; i--) {
const deleteButton = page.locator(`[data-testid="delete-button-${i}"]`)
await deleteButton.click()
await saveButton.click()
await page.reload()
dateInputs = page.locator('[data-testid="date-input-field"]')
await expect(dateInputs).toHaveCount(i)
}

const deletedTimeBoundariesResponse = await page.request.get(
`/api/v1/norms/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/timeBoundaries`,
{
headers: {
Accept: "application/json",
},
},
)
const timeboundaries = await deletedTimeBoundariesResponse.json()

expect(timeboundaries).toEqual([
{ date: "2017-03-16", eventRefEid: "meta-1_lebzykl-1_ereignis-2" },
])

const deleteButton = page.locator(`[data-testid="delete-button-0"]`)
const isDisabled = await deleteButton.isDisabled()
expect(isDisabled).toBe(true)

await page.request.put(
`/api/v1/norms/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/timeBoundaries`,
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
data: JSON.stringify([
{ date: "2017-03-16", eventRefEid: "meta-1_lebzykl-1_ereignis-2" },
]),
},
)
})
})