@webship-js/immich-steps 0.0.0-stage → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +251 -2
- package/assets/logo.svg +29 -0
- package/package.json +62 -4
- package/tests/features/albums.feature +26 -0
- package/tests/features/api.feature +30 -0
- package/tests/features/library.feature +46 -0
- package/tests/features/sign-in.feature +26 -0
- package/tests/fixtures/webship-test-blue.jpg +0 -0
- package/tests/fixtures/webship-test-green.jpg +0 -0
- package/tests/fixtures/webship-test-red.jpg +0 -0
- package/tests/step-definitions/immich-albums.steps.js +213 -0
- package/tests/step-definitions/immich-auth.steps.js +286 -0
- package/tests/step-definitions/immich-helpers.js +453 -0
- package/tests/step-definitions/immich-library.steps.js +437 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Albums, shared links and search: an album made with a photo, as a person makes it; an album's link shared and
|
|
4
|
+
// opened by someone who is not signed in; and the library's search by file name (its default search reads what a
|
|
5
|
+
// photo shows, which needs machine learning: without it, the words are not read).
|
|
6
|
+
|
|
7
|
+
const { When, Then } = require('@cucumber/cucumber');
|
|
8
|
+
const h = require('./immich-helpers');
|
|
9
|
+
|
|
10
|
+
const { friendly, failure } = h;
|
|
11
|
+
|
|
12
|
+
/** An album of the signed-in browser's account, by its name, through the library's API (the page's own session). */
|
|
13
|
+
async function albumNamed(world, name) {
|
|
14
|
+
const answer = await h.request(world, 'GET', '/api/albums', { session: true });
|
|
15
|
+
const albums = Array.isArray(answer.data) ? answer.data : [];
|
|
16
|
+
const album = albums.find((a) => a.albumName === name);
|
|
17
|
+
if (!album) {
|
|
18
|
+
throw failure(world.page, `Expected an album "${name}", but the library has ${albums.length ? albums.map((a) => `"${a.albumName}"`).join(', ') : 'none'}${answer.status === 401 ? ' (the browser is not signed in)' : ''}.`, {
|
|
19
|
+
hint: answer.status === 401 ? 'Sign in first: Given I am signed in to the library as "user".' : 'Make it first: When I create the album "…" with the photo taken on "…".',
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return album;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Make an album with a photo, as a person does: Albums, "Create album" (the library makes an untitled album at
|
|
27
|
+
* once), its title, "Select photos", the photo taken on the date, "Add assets". Name it "Webship test …" so
|
|
28
|
+
* @removes-test-content removes it after.
|
|
29
|
+
*
|
|
30
|
+
* Example #1: When I create the album "Webship test album" with the photo taken on "May 1, 2024"
|
|
31
|
+
* Example #2: When we create the album "Webship test holidays" with the photo taken on "August 15, 2023"
|
|
32
|
+
* Example #3: And I create the album "Webship test album" with the photo taken on "December 24, 2022"
|
|
33
|
+
* Example #4: When I create the album "Webship test family" with the photo taken on "January 9, 2021"
|
|
34
|
+
* Example #5: Given I create the album "Webship test album" with the photo taken on "May 1, 2024"
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
When(/^(?:I|we) create the album "([^"]+)" with the photo taken on "([^"]+)"$/, async function (name, date) {
|
|
38
|
+
const page = this.page;
|
|
39
|
+
await h.open(this, '/albums');
|
|
40
|
+
const create = page.getByRole('button', { name: 'Create album', exact: true });
|
|
41
|
+
try {
|
|
42
|
+
await create.waitFor({ state: 'visible', timeout: h.WAIT.page });
|
|
43
|
+
} catch (e) {
|
|
44
|
+
throw failure(page, `Expected the library's albums with a "Create album" button, but the page is ${page.url()}.`, { hint: 'Sign in first: Given I am signed in to the library as "user".' });
|
|
45
|
+
}
|
|
46
|
+
const made = await h.callOf(page, 'POST', /^\/api\/albums$/, () => create.click());
|
|
47
|
+
if (!made || made.status() !== 201) {
|
|
48
|
+
throw failure(page, `Expected the library to make an album, but it ${made ? `answered ${made.status()}` : 'did not answer'}.`, { hint: 'Check that the account may make albums.' });
|
|
49
|
+
}
|
|
50
|
+
const title = page.getByRole('textbox', { name: 'Edit Title' });
|
|
51
|
+
await title.waitFor({ state: 'visible', timeout: h.WAIT.page });
|
|
52
|
+
await title.fill(name);
|
|
53
|
+
const named = await h.callOf(page, 'PATCH', /^\/api\/albums\/[^/]+$/, () => title.press('Enter'));
|
|
54
|
+
if (!named || named.status() !== 200) {
|
|
55
|
+
throw failure(page, `Expected the library to name the album "${name}", but it ${named ? `answered ${named.status()}` : 'did not answer'}.`, { hint: 'Check the name: the library takes any text.' });
|
|
56
|
+
}
|
|
57
|
+
await page.getByRole('button', { name: 'Select photos', exact: true }).click();
|
|
58
|
+
if (!(await h.photoShows(page, date))) {
|
|
59
|
+
const shown = await h.photosShown(page);
|
|
60
|
+
throw failure(page, `Expected the album's picker to offer the photo taken on "${date}", but it offers ${shown.length ? shown.map((d) => `"${d}"`).join(', ') : 'no photo'}.`, { hint: 'Upload it first, as the same account.' });
|
|
61
|
+
}
|
|
62
|
+
await h.photo(page, date).first().click();
|
|
63
|
+
const add = page.getByRole('button', { name: 'Add assets', exact: true });
|
|
64
|
+
await add.waitFor({ state: 'visible', timeout: h.WAIT.message });
|
|
65
|
+
const added = await h.callOf(page, 'PUT', /^\/api\/albums\/[^/]+\/assets$/, () => add.click());
|
|
66
|
+
if (!added || added.status() !== 200) {
|
|
67
|
+
throw failure(page, `Expected the library to add the photo taken on "${date}" to the album "${name}", but it ${added ? `answered ${added.status()}` : 'did not answer'}.`, { hint: 'Check the library\'s log.' });
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* An album holds a number of photos and videos ("1 item", "3 items"), on its own page.
|
|
73
|
+
*
|
|
74
|
+
* Example #1: Then the album "Webship test album" should hold 1 item
|
|
75
|
+
* Example #2: And the album "Webship test holidays" should hold 2 items
|
|
76
|
+
* Example #3: Then the album "Webship test album" should hold 0 items
|
|
77
|
+
* Example #4: Then the album "Webship test family" should hold 3 items
|
|
78
|
+
* Example #5: But the album "Webship test album" should hold 1 item
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
Then(/^the album "([^"]+)" should hold (\d+) items?$/, async function (name, count) {
|
|
82
|
+
const album = await albumNamed(this, name);
|
|
83
|
+
await h.open(this, `/albums/${album.id}`);
|
|
84
|
+
const text = `${count} item${Number(count) === 1 ? '' : 's'}`;
|
|
85
|
+
if (!(await h.messageShown(this.page, text, h.WAIT.page))) {
|
|
86
|
+
const shown = await this.page.getByText(/\d+ items?/).allInnerTexts().catch(() => []);
|
|
87
|
+
throw failure(this.page, `Expected the album "${name}" to hold ${text}, but its page says ${shown.length ? `"${shown[0].trim()}"` : 'no count'}.`, { hint: 'Add the photo to it in the scenario first.' });
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Share an album by a link anyone can open: its Share, "Create link", the link's description "Webship test link",
|
|
93
|
+
* "Create link". The link is kept for: When I open the shared link signed out. @removes-test-content removes it after.
|
|
94
|
+
*
|
|
95
|
+
* Example #1: When I share the album "Webship test album" by a link
|
|
96
|
+
* Example #2: When we share the album "Webship test holidays" by a link
|
|
97
|
+
* Example #3: And I share the album "Webship test album" by a link
|
|
98
|
+
* Example #4: When I share the album "Webship test family" by a link
|
|
99
|
+
* Example #5: Given I share the album "Webship test album" by a link
|
|
100
|
+
*
|
|
101
|
+
*/
|
|
102
|
+
When(/^(?:I|we) share the album "([^"]+)" by a link$/, async function (name) {
|
|
103
|
+
const page = this.page;
|
|
104
|
+
const album = await albumNamed(this, name);
|
|
105
|
+
await h.open(this, `/albums/${album.id}`);
|
|
106
|
+
await page.getByRole('button', { name: 'Share', exact: true }).click();
|
|
107
|
+
const options = await h.dialog(page);
|
|
108
|
+
if (!options) throw failure(page, `Expected the album's sharing options, but no dialog opened.`, { hint: 'Check that the account owns the album.' });
|
|
109
|
+
await options.getByRole('button', { name: 'Create link', exact: true }).click();
|
|
110
|
+
const form = await h.dialog(page);
|
|
111
|
+
await form.getByRole('textbox', { name: 'Description' }).fill('Webship test link');
|
|
112
|
+
const answer = await h.callOf(page, 'POST', /^\/api\/shared-links$/, () => form.getByRole('button', { name: 'Create link', exact: true }).click());
|
|
113
|
+
if (!answer || answer.status() !== 201) {
|
|
114
|
+
throw failure(page, `Expected the library to make a link to the album "${name}", but it ${answer ? `answered ${answer.status()}` : 'did not answer'}.`, { hint: 'Check that shared links are on in the library\'s settings.' });
|
|
115
|
+
}
|
|
116
|
+
const link = await answer.json();
|
|
117
|
+
this.immichSharedLink = { key: link.key, slug: link.slug, album: name };
|
|
118
|
+
await page.keyboard.press('Escape').catch(() => {});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Open the shared link the scenario made as someone who is not signed in: a browser context of its own, with no
|
|
123
|
+
* session. The steps about the shared page read that page.
|
|
124
|
+
*
|
|
125
|
+
* Example #1: When I open the shared link signed out
|
|
126
|
+
* Example #2: When we open the shared link signed out
|
|
127
|
+
* Example #3: And I open the shared link signed out
|
|
128
|
+
* Example #4: Then I open the shared link signed out
|
|
129
|
+
* Example #5: Given we open the shared link signed out
|
|
130
|
+
*
|
|
131
|
+
*/
|
|
132
|
+
When(/^(?:I|we) open the shared link signed out$/, async function () {
|
|
133
|
+
if (!this.immichSharedLink) {
|
|
134
|
+
throw friendly({ message: 'There is no shared link to open: the scenario has not made one.', hint: 'Make it first: When I share the album "…" by a link.' });
|
|
135
|
+
}
|
|
136
|
+
const browser = this.page.context().browser();
|
|
137
|
+
this.immichSharedContext = await browser.newContext({ viewport: this.page.viewportSize() || { width: 1280, height: 860 }, ignoreHTTPSErrors: true });
|
|
138
|
+
this.immichSharedPage = await this.immichSharedContext.newPage();
|
|
139
|
+
const address = h.absolute(this, `/share/${this.immichSharedLink.slug || this.immichSharedLink.key}`);
|
|
140
|
+
const answer = await this.immichSharedPage.goto(address, { waitUntil: 'domcontentloaded' });
|
|
141
|
+
await this.immichSharedPage.waitForLoadState('networkidle', { timeout: h.WAIT.page }).catch(() => {});
|
|
142
|
+
if (!answer || answer.status() >= 400) {
|
|
143
|
+
throw failure(this.immichSharedPage, `Expected the shared link to open, but ${address.replace(/\/share\/.*/, '/share/…')} answered ${answer ? answer.status() : 'nothing'}.`, { hint: 'The link may have expired, or been removed.' });
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The shared page (opened signed out) shows a photo taken on a date.
|
|
149
|
+
*
|
|
150
|
+
* Example #1: Then the shared page should show the photo taken on "May 1, 2024"
|
|
151
|
+
* Example #2: And the shared page should show the photo taken on "August 15, 2023"
|
|
152
|
+
* Example #3: Then the shared page should show the photo taken on "December 24, 2022"
|
|
153
|
+
* Example #4: Then the shared page should show the photo taken on "January 9, 2021"
|
|
154
|
+
* Example #5: But the shared page should show the photo taken on "May 1, 2024"
|
|
155
|
+
*
|
|
156
|
+
*/
|
|
157
|
+
Then(/^the shared page should show the photo taken on "([^"]+)"$/, async function (date) {
|
|
158
|
+
const page = this.immichSharedPage;
|
|
159
|
+
if (!page) throw friendly({ message: 'No shared page is open.', hint: 'Open it first: When I open the shared link signed out.' });
|
|
160
|
+
if (!(await h.photoShows(page, date))) {
|
|
161
|
+
const shown = await h.photosShown(page);
|
|
162
|
+
throw failure(page, `Expected the shared page to show the photo taken on "${date}", but it shows ${shown.length ? shown.map((d) => `"${d}"`).join(', ') : 'no photo'}.`, { hint: 'Add the photo to the shared album first.' });
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Search the library by a file name (or the start of one): its File name search, which the step chooses. The
|
|
168
|
+
* library's default search reads what a photo shows, which needs machine learning; without it, its words are not
|
|
169
|
+
* read and every photo comes back.
|
|
170
|
+
*
|
|
171
|
+
* Example #1: When I search the library for the file name "webship-test-blue"
|
|
172
|
+
* Example #2: When we search the library for the file name "webship-test-red.jpg"
|
|
173
|
+
* Example #3: And I search the library for the file name "webship-test"
|
|
174
|
+
* Example #4: When I search the library for the file name "holiday-2024"
|
|
175
|
+
* Example #5: Given I search the library for the file name "webship-test-green"
|
|
176
|
+
*
|
|
177
|
+
*/
|
|
178
|
+
When(/^(?:I|we) search the library for the file name "([^"]+)"$/, async function (name) {
|
|
179
|
+
const page = this.page;
|
|
180
|
+
const query = encodeURIComponent(JSON.stringify({ originalFileName: name }));
|
|
181
|
+
const answer = await h.callOf(page, 'POST', /^\/api\/search\/metadata$/, () => page.goto(h.absolute(this, `/search?query=${query}`), { waitUntil: 'domcontentloaded' }));
|
|
182
|
+
if (!answer || answer.status() !== 200) {
|
|
183
|
+
throw failure(page, `Expected the library to search for the file name "${name}", but it ${answer ? `answered ${answer.status()}` : 'sent no search'}.`, { hint: 'Sign in first: Given I am signed in to the library as "user".' });
|
|
184
|
+
}
|
|
185
|
+
this.immichSearch = { name, found: ((await answer.json()).assets || {}).total };
|
|
186
|
+
await page.waitForLoadState('networkidle').catch(() => {});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* The search finds a photo taken on a date, or finds nothing.
|
|
191
|
+
*
|
|
192
|
+
* Example #1: Then the search should find the photo taken on "August 15, 2023"
|
|
193
|
+
* Example #2: And the search should find the photo taken on "May 1, 2024"
|
|
194
|
+
* Example #3: Then the search should find the photo taken on "December 24, 2022"
|
|
195
|
+
* Example #4: Then the search should find nothing
|
|
196
|
+
* Example #5: But the search should find nothing
|
|
197
|
+
*
|
|
198
|
+
*/
|
|
199
|
+
Then(/^the search should (?:find the photo taken on "([^"]+)"|find nothing)$/, async function (date) {
|
|
200
|
+
const page = this.page;
|
|
201
|
+
if (!this.immichSearch) throw friendly({ message: 'The scenario has not searched.', hint: 'Search first: When I search the library for the file name "…".' });
|
|
202
|
+
if (date) {
|
|
203
|
+
if (!(await h.photoShows(page, date))) {
|
|
204
|
+
const shown = await h.photosShown(page);
|
|
205
|
+
throw failure(page, `Expected the search for "${this.immichSearch.name}" to find the photo taken on "${date}", but it finds ${shown.length ? shown.map((d) => `"${d}"`).join(', ') : 'nothing'}.`, { hint: 'The search is by the file\'s original name, from its start.' });
|
|
206
|
+
}
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const shown = await h.photosShown(page);
|
|
210
|
+
if (this.immichSearch.found || shown.length) {
|
|
211
|
+
throw failure(page, `Expected the search for "${this.immichSearch.name}" to find nothing, but it finds ${shown.length ? shown.map((d) => `the photo taken on "${d}"`).join(', ') : `${this.immichSearch.found} item(s)`}.`, { hint: 'Search for a name no file of the library has.' });
|
|
212
|
+
}
|
|
213
|
+
});
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Signing in to the library: through its login form, through the API for speed (the session's cookies put in the
|
|
4
|
+
// browser), with a token or an API key for webship-js's API steps; getting past the first-run wizard an account
|
|
5
|
+
// meets on its first sign-in; and a new account a scenario makes and removes.
|
|
6
|
+
//
|
|
7
|
+
// The hooks of @removes-test-content are here too: before the scenario, what an earlier run left is removed and the
|
|
8
|
+
// counts of every account of the users registry are taken; after it, what the scenario made (files webship-test-*,
|
|
9
|
+
// albums, shared links and API keys "Webship test …", accounts webship.test.…@example.com) is removed and the counts
|
|
10
|
+
// must be back where they were.
|
|
11
|
+
|
|
12
|
+
const { When, Given, Before, After } = require('@cucumber/cucumber');
|
|
13
|
+
const h = require('./immich-helpers');
|
|
14
|
+
|
|
15
|
+
const { friendly, failure } = h;
|
|
16
|
+
|
|
17
|
+
/** Fill in the login form and send it; the sign-in's answer. */
|
|
18
|
+
async function sendLoginForm(world, email, password) {
|
|
19
|
+
await h.open(world, '/auth/login');
|
|
20
|
+
const page = world.page;
|
|
21
|
+
const field = page.getByRole('textbox', { name: 'Email' });
|
|
22
|
+
try {
|
|
23
|
+
await field.waitFor({ state: 'visible', timeout: h.WAIT.page });
|
|
24
|
+
} catch (e) {
|
|
25
|
+
throw failure(page, `Expected the library's login form at ${h.absolute(world, '/auth/login')}, but the page has no "Email" field (it is at ${page.url()}).`, {
|
|
26
|
+
hint: page.url().includes('/auth/login') ? 'Check that the launch URL of cucumber.js is the library\'s address.' : 'A session is open already: sign out first, or use a browser of its own.',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
await field.fill(email);
|
|
30
|
+
await page.getByRole('textbox', { name: 'Password' }).fill(password);
|
|
31
|
+
const answer = await h.callOf(page, 'POST', /^\/api\/auth\/login$/, () => page.getByRole('button', { name: 'Login', exact: true }).click());
|
|
32
|
+
if (!answer) {
|
|
33
|
+
throw failure(page, 'Expected the library to answer the login form, but it sent no sign-in within the wait.', {
|
|
34
|
+
hint: 'Check that the library is up, and that the form\'s button is "Login".',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return answer;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Sign an account of the users registry in through the library's login form, as a person does: the email address,
|
|
42
|
+
* the password, "Login"; then the library's first page after it (the timeline, or the first-run wizard of an account
|
|
43
|
+
* that has not met it yet).
|
|
44
|
+
*
|
|
45
|
+
* Example #1: When I sign in to the library as "user"
|
|
46
|
+
* Example #2: When we sign in to the library as "admin"
|
|
47
|
+
* Example #3: And I sign in to the library as "newcomer"
|
|
48
|
+
* Example #4: When I sign in to the library as "editor"
|
|
49
|
+
* Example #5: Given I sign in to the library as "user"
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
When(/^(?:I|we) sign in to the library as "([^"]+)"$/, async function (handle) {
|
|
53
|
+
const account = h.user(this, handle);
|
|
54
|
+
const answer = await sendLoginForm(this, account.email, account.password);
|
|
55
|
+
if (answer.status() !== 201) {
|
|
56
|
+
let message = '';
|
|
57
|
+
try { message = (await answer.json()).message || ''; } catch (e) { /* not JSON */ }
|
|
58
|
+
throw failure(this.page, `Expected the library to sign "${handle}" (${account.email}) in, but it answered ${answer.status()}${message ? `: "${message}"` : ''}.`, {
|
|
59
|
+
hint: answer.status() === 401 ? `Check the password of "${handle}" in the users registry (worldParameters.users.${handle}.password).` : 'Check the account in the library\'s User Management.',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
await this.page.waitForURL((url) => !url.pathname.startsWith('/auth/login'), { timeout: h.WAIT.page });
|
|
64
|
+
} catch (e) {
|
|
65
|
+
throw failure(this.page, `Expected the library to leave its login page once "${handle}" was signed in, but it stayed at ${this.page.url()}.`, {
|
|
66
|
+
hint: 'Check the library\'s log: the sign-in was accepted, the page did not follow.',
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (!this.immichSignedIn) this.immichSignedIn = new Set();
|
|
70
|
+
this.immichSignedIn.add(handle);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Send the login form of an account with a password that is not its own, to see what the library says. The step
|
|
75
|
+
* passes when the library refuses it; read its message with: Then the library should say "Incorrect email or password".
|
|
76
|
+
*
|
|
77
|
+
* Example #1: When I sign in to the library as "user" with a wrong password
|
|
78
|
+
* Example #2: When we sign in to the library as "admin" with a wrong password
|
|
79
|
+
* Example #3: And I sign in to the library as "newcomer" with a wrong password
|
|
80
|
+
* Example #4: When I sign in to the library as "editor" with a wrong password
|
|
81
|
+
* Example #5: Given I sign in to the library as "user" with a wrong password
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
When(/^(?:I|we) sign in to the library as "([^"]+)" with a wrong password$/, async function (handle) {
|
|
85
|
+
const account = h.user(this, handle);
|
|
86
|
+
const answer = await sendLoginForm(this, account.email, `${account.password}-but-wrong`);
|
|
87
|
+
if (answer.status() === 201) {
|
|
88
|
+
throw failure(this.page, `Expected the library to refuse a wrong password for "${handle}" (${account.email}), but it signed the account in.`, {
|
|
89
|
+
hint: 'The account must not take any password: check how the library signs its accounts in.',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Sign an account in through the API (faster than the form) and open the library in the browser with its session:
|
|
96
|
+
* its cookies go to the browser, then its timeline opens. An account that has not met the first-run wizard lands on
|
|
97
|
+
* it: When I get past the library's first-run wizard.
|
|
98
|
+
*
|
|
99
|
+
* Example #1: Given I am signed in to the library as "user"
|
|
100
|
+
* Example #2: Given we are signed in to the library as "admin"
|
|
101
|
+
* Example #3: And I am signed in to the library as "newcomer"
|
|
102
|
+
* Example #4: Given I am signed in to the library as "editor"
|
|
103
|
+
* Example #5: Given we are signed in to the library as "user"
|
|
104
|
+
*
|
|
105
|
+
*/
|
|
106
|
+
Given(/^(?:I am|we are) signed in to the library as "([^"]+)"$/, async function (handle) {
|
|
107
|
+
await h.signIn(this, handle, { session: true });
|
|
108
|
+
await h.open(this, '/photos');
|
|
109
|
+
if (this.page.url().includes('/auth/login')) {
|
|
110
|
+
throw failure(this.page, `Expected the library to open signed in as "${handle}", but it showed its login page.`, {
|
|
111
|
+
hint: 'The session\'s cookies did not reach the browser: check that the launch URL is the address the browser opens.',
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get past the first-run wizard an account meets on its first sign-in (theme, language, privacy, storage, backups,
|
|
118
|
+
* the mobile app), with what each step offers already chosen, to the timeline. The accounts the Webship Workspace
|
|
119
|
+
* makes have met it already; a library's own may not have.
|
|
120
|
+
*
|
|
121
|
+
* Example #1: When I get past the library's first-run wizard
|
|
122
|
+
* Example #2: And we get past the library's first-run wizard
|
|
123
|
+
* Example #3: When I get past the library's first-run wizard
|
|
124
|
+
* Example #4: Then I get past the library's first-run wizard
|
|
125
|
+
* Example #5: Given we get past the library's first-run wizard
|
|
126
|
+
*
|
|
127
|
+
*/
|
|
128
|
+
When(/^(?:I|we) get past the library's first-run wizard$/, async function () {
|
|
129
|
+
const page = this.page;
|
|
130
|
+
try {
|
|
131
|
+
await page.waitForURL((url) => url.pathname.startsWith('/auth/onboarding'), { timeout: h.WAIT.page });
|
|
132
|
+
} catch (e) {
|
|
133
|
+
throw failure(page, `Expected the library's first-run wizard, but the page is ${page.url()}.`, {
|
|
134
|
+
hint: 'The account has met it already: the step is for an account on its first sign-in.',
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const seen = [];
|
|
138
|
+
for (let i = 0; i < 20 && new URL(page.url()).pathname.startsWith('/auth/onboarding'); i += 1) {
|
|
139
|
+
const buttons = await page.getByRole('button').evaluateAll((list) => list.filter((b) => b.offsetParent !== null).map((b) => (b.getAttribute('aria-label') || b.innerText || '').trim()).filter(Boolean));
|
|
140
|
+
const next = buttons.includes('Done') ? 'Done' : buttons[buttons.length - 1];
|
|
141
|
+
if (!next) break;
|
|
142
|
+
seen.push(next);
|
|
143
|
+
await page.getByRole('button', { name: next, exact: true }).last().click();
|
|
144
|
+
await page.waitForLoadState('networkidle').catch(() => {});
|
|
145
|
+
await h.pause(300);
|
|
146
|
+
}
|
|
147
|
+
if (new URL(page.url()).pathname.startsWith('/auth/onboarding')) {
|
|
148
|
+
throw failure(page, `Expected the first-run wizard to end, but it is still at ${page.url()} after: ${seen.join(' → ')}.`, {
|
|
149
|
+
hint: 'A step of the wizard asks for something the step cannot choose: complete it by hand once, or onboard the account through the API.',
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Sign the requests of webship-js's API steps (and of this pack's API steps) as an account: its bearer token, from
|
|
156
|
+
* the library's sign-in. Send them to the library with: Given the API base URL is "/".
|
|
157
|
+
*
|
|
158
|
+
* Example #1: Given I am signed in to the library's API as "user"
|
|
159
|
+
* Example #2: Given we are signed in to the library's API as "admin"
|
|
160
|
+
* Example #3: And I am signed in to the library's API as "newcomer"
|
|
161
|
+
* Example #4: Given I am signed in to the library's API as "editor"
|
|
162
|
+
* Example #5: Given we are signed in to the library's API as "user"
|
|
163
|
+
*
|
|
164
|
+
*/
|
|
165
|
+
Given(/^(?:I am|we are) signed in to the library's API as "([^"]+)"$/, async function (handle) {
|
|
166
|
+
const token = await h.signIn(this, handle);
|
|
167
|
+
h.signApi(this, 'Authorization', `Bearer ${token}`);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Sign the requests of the API steps with an API key of an account instead: a key named "Webship test key" with every
|
|
172
|
+
* permission, made for the scenario through the API and sent as `x-api-key`. @removes-test-content removes it after.
|
|
173
|
+
*
|
|
174
|
+
* Example #1: Given the library's API uses a key of "user"
|
|
175
|
+
* Example #2: Given the library's API uses a key of "admin"
|
|
176
|
+
* Example #3: And the library's API uses a key of "newcomer"
|
|
177
|
+
* Example #4: Given the library's API uses a key of "editor"
|
|
178
|
+
* Example #5: When the library's API uses a key of "user"
|
|
179
|
+
*
|
|
180
|
+
*/
|
|
181
|
+
Given(/^the library's API uses a key of "([^"]+)"$/, async function (handle) {
|
|
182
|
+
const token = await h.tokenOf(this, handle);
|
|
183
|
+
const answer = await h.request(this, 'POST', '/api/api-keys', { token, json: { name: 'Webship test key', permissions: ['all'] } });
|
|
184
|
+
if (answer.status !== 201 || !answer.data || !answer.data.secret) {
|
|
185
|
+
throw friendly({
|
|
186
|
+
message: `Expected the library to make an API key for "${handle}", but it answered ${answer.status}: ${h.said(answer)}.`,
|
|
187
|
+
hint: 'Check that the account may make API keys (Account Settings, API Keys).',
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
h.signApi(this, 'x-api-key', answer.data.secret);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* A new account in the library, for a scenario that needs one of its own: "Webship test <handle>", with the address
|
|
195
|
+
* webship.test.<handle>.<number>@example.com and a password of its own, made by the managing account
|
|
196
|
+
* (worldParameters.immich.manager) through the admin API. The scenario names it by its handle, like an account of the
|
|
197
|
+
* users registry; @removes-test-content removes it after.
|
|
198
|
+
*
|
|
199
|
+
* Example #1: Given the library has a new account "newcomer"
|
|
200
|
+
* Example #2: Given the library has a new account "guest"
|
|
201
|
+
* Example #3: And the library has a new account "reviewer"
|
|
202
|
+
* Example #4: Given the library has a new account "visitor"
|
|
203
|
+
* Example #5: Given the library has a new account "newcomer2"
|
|
204
|
+
*
|
|
205
|
+
*/
|
|
206
|
+
Given(/^the library has a new account "([a-z0-9][a-z0-9-]*)"$/, async function (handle) {
|
|
207
|
+
const manager = h.settings(this).manager;
|
|
208
|
+
const token = await h.tokenOf(this, manager);
|
|
209
|
+
const email = `webship.test.${handle}.${Date.now()}@example.com`;
|
|
210
|
+
const password = `Webship-test-${Math.random().toString(36).slice(2, 12)}-${Date.now() % 100000}`;
|
|
211
|
+
const answer = await h.request(this, 'POST', '/api/admin/users', { token, json: { email, password, name: `Webship test ${handle}`, shouldChangePassword: false } });
|
|
212
|
+
if (answer.status !== 201) {
|
|
213
|
+
throw friendly({
|
|
214
|
+
message: `Expected the library to make the account "${handle}", but ${manager} was answered ${answer.status}: ${h.said(answer)}.`,
|
|
215
|
+
hint: `The managing account (worldParameters.immich.manager, "${manager}") must be an admin of the library.`,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
if (!this.immichAccounts) this.immichAccounts = {};
|
|
219
|
+
this.immichAccounts[handle] = { handle, email, password };
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// ---------------------------------------------------------------------------
|
|
223
|
+
// @removes-test-content
|
|
224
|
+
// ---------------------------------------------------------------------------
|
|
225
|
+
|
|
226
|
+
/** The accounts of the users registry that can sign in (an email and a password). */
|
|
227
|
+
function registry(world) {
|
|
228
|
+
const users = (world.parameters && world.parameters.users) || {};
|
|
229
|
+
return Object.keys(users).filter((handle) => (users[handle].email || users[handle].username) && users[handle].password);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** The counts of every account, read again until they match `expected` or the budget runs out (removals are jobs). */
|
|
233
|
+
async function settle(world, expected) {
|
|
234
|
+
let now = {};
|
|
235
|
+
for (let i = 0; i < 20; i += 1) {
|
|
236
|
+
now = {};
|
|
237
|
+
for (const handle of Object.keys(expected)) now[handle] = await h.counts(world, handle);
|
|
238
|
+
if (JSON.stringify(now) === JSON.stringify(expected)) return now;
|
|
239
|
+
await h.pause(750);
|
|
240
|
+
}
|
|
241
|
+
return now;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
Before({ tags: '@removes-test-content' }, async function () {
|
|
245
|
+
this.immichCounts = {};
|
|
246
|
+
for (const handle of registry(this)) {
|
|
247
|
+
await h.removeTestContent(this, handle);
|
|
248
|
+
}
|
|
249
|
+
for (const handle of registry(this)) {
|
|
250
|
+
this.immichCounts[handle] = await h.counts(this, handle);
|
|
251
|
+
}
|
|
252
|
+
this.immichCounts = await settle(this, this.immichCounts);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
After(async function () {
|
|
256
|
+
if (this.immichSharedContext) {
|
|
257
|
+
await this.immichSharedContext.close().catch(() => {});
|
|
258
|
+
this.immichSharedContext = null;
|
|
259
|
+
this.immichSharedPage = null;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
After({ tags: '@removes-test-content' }, async function (scenario) {
|
|
264
|
+
if (!this.immichCounts) return;
|
|
265
|
+
// A page still open on what is about to be removed asks the library for it again and logs the 400 it gets as a
|
|
266
|
+
// console error: after a scenario that passed, the page leaves first. A failed one keeps its page, for the
|
|
267
|
+
// screenshot of the failure.
|
|
268
|
+
if (scenario.result && scenario.result.status === 'PASSED' && this.page) await this.page.goto('about:blank').catch(() => {});
|
|
269
|
+
const removed = await h.removeMade(this);
|
|
270
|
+
for (const handle of Object.keys(this.immichCounts)) {
|
|
271
|
+
removed.push(...(await h.removeTestContent(this, handle)).map((r) => `${handle}: ${r}`));
|
|
272
|
+
}
|
|
273
|
+
const now = await settle(this, this.immichCounts);
|
|
274
|
+
const differences = [];
|
|
275
|
+
for (const [handle, before] of Object.entries(this.immichCounts)) {
|
|
276
|
+
for (const [what, count] of Object.entries(before)) {
|
|
277
|
+
if ((now[handle] || {})[what] !== count) differences.push(`${handle}'s ${what}: ${count} before, ${(now[handle] || {})[what]} after`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (differences.length && scenario.result && scenario.result.status === 'PASSED') {
|
|
281
|
+
throw friendly({
|
|
282
|
+
message: `The scenario left the library changed after its test content was removed (${removed.join(', ') || 'nothing to remove'}): ${differences.join('; ')}.`,
|
|
283
|
+
hint: 'Name what a scenario makes so the pack can find it: upload files named webship-test-*, and call albums, shared links and keys "Webship test …".',
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
});
|