Skip to content

Commit a87045a

Browse files
Pollepsjoepio
authored andcommitted
Prune testdrives before running e2e
1 parent 124ee58 commit a87045a

File tree

12 files changed

+163
-6
lines changed

12 files changed

+163
-6
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Resource, Server, useStore } from '@tomic/react';
2+
import React, { useState } from 'react';
3+
import { Button } from '../components/Button';
4+
import { ContainerFull } from '../components/Containers';
5+
import { Column } from '../components/Row';
6+
7+
export function PruneTestsRoute(): JSX.Element {
8+
const store = useStore();
9+
const [result, setResult] = useState<Resource<Server.EndpointResponse>>();
10+
const [isWaiting, setIsWaiting] = useState(false);
11+
12+
const postPruneTest = async () => {
13+
setIsWaiting(true);
14+
const url = new URL('/prunetests', store.getServerUrl());
15+
const res = await store.postToServer(url.toString());
16+
setIsWaiting(false);
17+
setResult(res);
18+
};
19+
20+
return (
21+
<main>
22+
<ContainerFull>
23+
<h1>Prune Test Data</h1>
24+
<p>
25+
Pruning test data will delete all drives on the server that have
26+
&rsquo;testdrive&rsquo; in their name.
27+
</p>
28+
<Column>
29+
<Button onClick={postPruneTest} disabled={isWaiting} alert>
30+
Prune
31+
</Button>
32+
{isWaiting && <p>Pruning, this might take a while...</p>}
33+
<p data-testId='prune-result'>
34+
{result && `✅ ${result.props.responseMessage}`}
35+
</p>
36+
</Column>
37+
</ContainerFull>
38+
</main>
39+
);
40+
}

browser/data-browser/src/routes/Routes.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { Sandbox } from './Sandbox';
2020
import { TokenRoute } from './TokenRoute';
2121
import { ImporterPage } from '../views/ImporterPage';
2222
import { History } from './History';
23+
import { PruneTestsRoute } from './PruneTestsRoute';
2324

2425
const homeURL = window.location.origin;
2526

@@ -48,6 +49,7 @@ export function AppRoutes(): JSX.Element {
4849
<Route path={paths.search} element={<Search />} />
4950
<Route path={paths.token} element={<TokenRoute />} />
5051
<Route path={paths.history} element={<History />} />
52+
{isDev && <Route path={paths.pruneTests} element={<PruneTestsRoute />} />}
5153
{isDev && <Route path={paths.sandbox} element={<Sandbox />} />}
5254
<Route path='/' element={<ResourcePage subject={homeURL} />} />
5355
<Route path='*' element={<Local />} />

browser/data-browser/src/routes/paths.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export const paths = {
1616
allVersions: '/all-versions',
1717
sandbox: '/sandbox',
1818
fetchBookmark: '/fetch-bookmark',
19+
pruneTests: '/prunetests',
1920
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { test as setup, expect } from '@playwright/test';
2+
import { before, FRONTEND_URL, signIn } from './test-utils';
3+
4+
setup('delete previous test data', async ({ page }) => {
5+
await before({ page });
6+
await signIn(page);
7+
await page.goto(`${FRONTEND_URL}/prunetests`);
8+
await expect(page.getByText('Prune Test Data')).toBeVisible();
9+
await page.getByRole('button', { name: 'Prune' }).click();
10+
11+
await expect(page.getByTestId('prune-result')).toBeVisible();
12+
});

browser/data-browser/tests/playwright.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ const config: PlaywrightTestConfig = {
1111
retries: 3,
1212
// timeout: 1000 * 120, // 2 minutes
1313
projects: [
14+
{
15+
name: 'setup',
16+
testMatch: /global.setup\.ts/,
17+
},
1418
{
1519
name: 'chromium',
1620
use: { ...devices['Desktop Chrome'] },
21+
dependencies: ['setup'],
1722
},
1823
],
1924
// projects: [

browser/lib/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class Client {
128128
subject: string,
129129
opts: FetchResourceOptions = {},
130130
): Promise<HTTPResourceResult> {
131-
const { signInfo, from, body: bodyReq } = opts;
131+
const { signInfo, from, body: bodyReq, method } = opts;
132132
let createdResources: Resource[] = [];
133133
const parser = new JSONADParser();
134134
let resource = new Resource(subject);
@@ -160,7 +160,7 @@ export class Client {
160160

161161
const response = await this.fetch(url, {
162162
headers: requestHeaders,
163-
method: bodyReq ? 'POST' : 'GET',
163+
method: method ?? 'GET',
164164
body: bodyReq,
165165
});
166166
const body = await response.text();

browser/lib/src/ontologies/server.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export const server = {
1212
redirect: 'https://atomicdata.dev/classes/Redirect',
1313
file: 'https://atomicdata.dev/classes/File',
1414
invite: 'https://atomicdata.dev/classes/Invite',
15+
endpointResponse:
16+
'https://atomicdata.dev/ontology/server/class/endpoint-response',
1517
},
1618
properties: {
1719
drives: 'https://atomicdata.dev/properties/drives',
@@ -35,6 +37,9 @@ export const server = {
3537
children: 'https://atomicdata.dev/properties/children',
3638
parameters: 'https://atomicdata.dev/properties/endpoint/parameters',
3739
destination: 'https://atomicdata.dev/properties/destination',
40+
status: 'https://atomicdata.dev/ontology/server/property/status',
41+
responseMessage:
42+
'https://atomicdata.dev/ontology/server/property/response-message',
3843
},
3944
} as const;
4045

@@ -46,6 +51,7 @@ export namespace Server {
4651
export type Redirect = typeof server.classes.redirect;
4752
export type File = typeof server.classes.file;
4853
export type Invite = typeof server.classes.invite;
54+
export type EndpointResponse = typeof server.classes.endpointResponse;
4955
}
5056

5157
declare module '../index.js' {
@@ -92,6 +98,13 @@ declare module '../index.js' {
9298
| typeof server.properties.users
9399
| typeof server.properties.usagesLeft;
94100
};
101+
[server.classes.endpointResponse]: {
102+
requires:
103+
| BaseProps
104+
| typeof server.properties.status
105+
| typeof server.properties.responseMessage;
106+
recommends: never;
107+
};
95108
}
96109

97110
interface PropTypeMapping {
@@ -116,6 +129,8 @@ declare module '../index.js' {
116129
[server.properties.children]: string[];
117130
[server.properties.parameters]: string[];
118131
[server.properties.destination]: string;
132+
[server.properties.status]: number;
133+
[server.properties.responseMessage]: string;
119134
}
120135

121136
interface PropSubjectToNameMapping {
@@ -140,5 +155,7 @@ declare module '../index.js' {
140155
[server.properties.children]: 'children';
141156
[server.properties.parameters]: 'parameters';
142157
[server.properties.destination]: 'destination';
158+
[server.properties.status]: 'status';
159+
[server.properties.responseMessage]: 'responseMessage';
143160
}
144161
}

browser/lib/src/store.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
FileOrFileLike,
1818
OptionalClass,
1919
UnknownClass,
20+
Server,
2021
} from './index.js';
2122
import { authenticate, fetchWebSocket, startWebsocket } from './websockets.js';
2223

@@ -533,10 +534,10 @@ export class Store {
533534
}
534535

535536
/** Sends an HTTP POST request to the server to the Subject. Parses the returned Resource and adds it to the store. */
536-
public async postToServer(
537+
public async postToServer<R extends OptionalClass = Server.EndpointResponse>(
537538
url: string,
538-
data: ArrayBuffer | string,
539-
): Promise<Resource> {
539+
data?: ArrayBuffer | string,
540+
): Promise<Resource<R>> {
540541
return this.fetchResourceFromServer(url, {
541542
body: data,
542543
noWebSocket: true,

lib/src/endpoints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,7 @@ pub fn default_endpoints() -> Vec<Endpoint> {
8585
plugins::bookmark::bookmark_endpoint(),
8686
plugins::importer::import_endpoint(),
8787
plugins::query::query_endpoint(),
88+
#[cfg(debug_assertions)]
89+
plugins::prunetests::prune_tests_endpoint(),
8890
]
8991
}

lib/src/plugins/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub mod invite;
4343
pub mod bookmark;
4444
pub mod files;
4545
pub mod path;
46+
pub mod prunetests;
4647
pub mod query;
4748
pub mod search;
4849
pub mod versioning;

0 commit comments

Comments
 (0)