-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from modern-sapien/storageStateWorkaround
Storage state workaround
- Loading branch information
Showing
14 changed files
with
225 additions
and
30 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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { | ||
MaintenanceWindow | ||
} from 'checkly/constructs'; | ||
|
||
// Maintenance Window | ||
export const maintenanceWindow = new MaintenanceWindow('next-danube-maintenance-window-1', { | ||
name: 'Next Danube Website Maintenance', | ||
// the tag determines what is created by | ||
tags: ['next-danube'], | ||
// 2023-07-20 at 11 PM EST in UTC | ||
startsAt: new Date(Date.UTC(2023, 6, 21, 4, 0, 0)), // Note: JavaScript's months are 0-indexed | ||
// 2023-07-21 at 12 AM EST in UTC | ||
endsAt: new Date(Date.UTC(2023, 6, 21, 5, 0, 0)), | ||
repeatInterval: 1, | ||
repeatUnit: 'MONTH', | ||
repeatEndsAt: new Date(new Date().valueOf() + (2160 * 60 * 60 * 1000)), // ~three months from now | ||
}) |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { test, expect } from "@playwright/test" | ||
import crypto from "crypto" | ||
|
||
test("Verify Binary Payloads", async ({ request }) => { | ||
// SpaceX Launch Images | ||
const IMAGES_TO_VERIFY = [ | ||
{ | ||
url: "https://farm1.staticflickr.com/856/28684550147_49802752b3_o.jpg", | ||
hash: "46df689c0016e4f06746f07b83546d5e", | ||
}, | ||
{ | ||
url: "https://farm1.staticflickr.com/927/28684552447_956a9744f1_o.jpg", | ||
hash: "ffb011da0c7cc45413c632ccd62947cf", | ||
}, | ||
{ | ||
url: "https://farm2.staticflickr.com/1828/29700007298_8ac5891d2c_o.jpg", | ||
hash: "eab74946120df579967922794e387276", | ||
}, | ||
{ | ||
url: "https://farm1.staticflickr.com/914/29700004918_31ed7b73ef_o.jpg", | ||
hash: "5e20e98a63522a0829aa5ad0003e52c6", | ||
}, | ||
] | ||
|
||
for (const [index, { url, hash }] of IMAGES_TO_VERIFY.entries()) { | ||
await test.step(`Fetch image #${index}`, async () => { | ||
const response = await request.get(url) | ||
|
||
const body = await response.body() | ||
expect(crypto.createHash("md5").update(body).digest("hex")).toBe(hash) | ||
}) | ||
} | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const { test, expect } = require('@playwright/test'); | ||
|
||
test.describe('GraphQL API Tests', () => { | ||
let apiContext; | ||
|
||
test.beforeAll(async ({ playwright }) => { | ||
apiContext = await playwright.request.newContext(); | ||
}); | ||
|
||
test('Test Dragons Query', async () => { | ||
const response = await apiContext.post('https://spacex-production.up.railway.app/', { | ||
data: { | ||
query: ` | ||
query Dragons { | ||
dragons { | ||
name | ||
first_flight | ||
diameter { | ||
feet | ||
} | ||
launch_payload_mass { | ||
lb | ||
} | ||
} | ||
} | ||
`, | ||
}, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
|
||
expect(response.ok()).toBeTruthy(); | ||
|
||
const responseBody = await response.json(); | ||
expect(responseBody).toHaveProperty('data.dragons'); | ||
expect(Array.isArray(responseBody.data.dragons)).toBeTruthy(); | ||
}); | ||
|
||
test('Test Ships Query', async () => { | ||
const response = await apiContext.post('https://spacex-production.up.railway.app/', { | ||
data: { | ||
query: ` | ||
query Ships { | ||
ships { | ||
id | ||
model | ||
name | ||
type | ||
status | ||
} | ||
} | ||
`, | ||
}, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
|
||
expect(response.ok()).toBeTruthy(); | ||
|
||
const responseBody = await response.json(); | ||
expect(responseBody).toHaveProperty('data.ships'); | ||
expect(Array.isArray(responseBody.data.ships)).toBeTruthy(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { request } from '@playwright/test'; | ||
|
||
export async function createChecklyContext(apiKey, accountID) { | ||
return await request.newContext({ | ||
baseURL: 'https://api.checklyhq.com/v1/', | ||
extraHTTPHeaders: { | ||
Authorization: `Bearer ${apiKey}`, | ||
'x-checkly-account': `${accountID}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createChecklyContext } from '../utils/checklyRequestContext'; | ||
|
||
export async function validateStorageState(apiKey, accountID) { | ||
const context = await createChecklyContext(apiKey, accountID); | ||
|
||
let responseTime = await context.get(`variables/DEV_COOKIE_TIME`); | ||
let responseData = await responseTime.json(); | ||
const variableUnixTime = responseData.value; // Assuming the value is already in seconds | ||
const unixCurrentTime = Math.floor(Date.now() / 1000); | ||
|
||
// Calculate the difference in seconds | ||
const differenceInSeconds = unixCurrentTime - variableUnixTime; | ||
|
||
// Check if the difference is greater than or equal to 3600 seconds (1 hour) | ||
if (differenceInSeconds >= 3600) { | ||
throw new Error('More than an hour has passed since DEV_COOKIE_TIME was updated.'); | ||
} else { | ||
let responseStorageState = await context.get(`variables/DEV_STORAGE_STATE`); | ||
let responseData = await responseStorageState.json(); | ||
const handledStorageState = JSON.parse(responseData.value); | ||
|
||
// Return the storage state | ||
return handledStorageState; | ||
} | ||
} |