Skip to content

Commit 7ef4083

Browse files
committed
test/test-data: use Service.createUser to provision jslibtest6 (proper email indexing)
testData.prepare was using a raw fetchPost to /reg/users with the legacy 'invitationtoken'/'languageCode' field names. On Dokku-deployed backends (dev-pryv2-single) this code path created the user but DID NOT populate the PlatformDB email->username index, causing [UEMX]/[UEMA] to fail (Service.userIdForEmail returning null for jslibtest6@pryv.io). Service.createUser (modern register endpoint with camelCase fields + hosting:'auto') exercises the same path Service.createUser callers use in production; that path properly indexes the email. Verified across all 4 validation tiers (local + pryv.me + dev-pryv2-single + cross-CMC): every backend's UEMA test now passes. Note on global pryv: load-helpers.js sets global.pryv before any test file loads, so the require here uses the global to avoid mocha's ESM loader getting confused by the relative path.
1 parent dc03f78 commit 7ef4083

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

test/test-data.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,31 @@ async function prepare () {
4242
console.log('Testing on ' + serviceInfo.name + ' > register: ' + serviceInfo.register);
4343
await getHost(serviceInfo);
4444
if (!await testUserExists(serviceInfo, username)) { // create user
45-
const host = await getHost(serviceInfo);
46-
45+
// Use Service.createUser (modern register endpoint) — properly
46+
// populates the platform email→username index so subsequent
47+
// `Service.userIdForEmail` lookups succeed. The legacy raw POST
48+
// path used to live here but it skipped the email-index step on
49+
// some platforms (notably Dokku-deployed dev backends), causing
50+
// [UEMX]/[UEMA] to fail.
51+
// `pryv` global is set by load-helpers.js. Avoid a static
52+
// require here — mocha's ESM loader gets confused by the relative
53+
// path resolution and throws ERR_MODULE_NOT_FOUND on /test/.
54+
const pryv = global.pryv || require('pryv');
55+
const service = new pryv.Service(serviceInfoUrl);
4756
try {
48-
// create user
49-
await fetchPost(host + 'users', {
57+
await service.createUser({
5058
appId: 'js-lib-test',
5159
username,
5260
password: username,
5361
email: username + '@pryv.io',
54-
invitationtoken: 'enjoy',
55-
languageCode: 'en',
62+
hosting: 'auto',
63+
language: 'en',
64+
invitationToken: 'enjoy',
5665
referer: 'test-suite'
5766
});
5867
} catch (e) {
5968
console.log('Failed creating user ', e);
60-
throw new Error('Failed creating user ' + host + 'users');
69+
throw new Error('Failed creating user via Service.createUser: ' + (e && (e.message || String(e))));
6170
}
6271
}
6372
const apiEndpoint = serviceInfo.api.replace('{username}', username);

0 commit comments

Comments
 (0)