-
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.
* refactor: data generation to include only projects and organisations * fix: improve deployment files and release * chore: data generation reduced to only needed data * feat: home page without counts and news test: fix home page tests chore: fix meta description for project and organisation pages
- Loading branch information
1 parent
5dbf3f8
commit e482b1e
Showing
25 changed files
with
1,631 additions
and
1,314 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import {faker} from '@faker-js/faker'; | ||
|
||
import {postToBackend} from './utils.js' | ||
|
||
export async function generateAccounts(orcids){ | ||
const accounts = await postAccountsToBackend(100); | ||
const ids = accounts.map(a => a.id) | ||
const logins = await postToBackend('/login_for_account', generateLoginForAccount(ids, orcids)) | ||
// console.log('accounts, login_for_accounts done'); | ||
return ids | ||
} | ||
|
||
export async function postAccountsToBackend(amount = 100) { | ||
const accounts = []; | ||
for (let i = 0; i < amount; i++) { | ||
accounts.push({ | ||
public_orcid_profile: !!faker.helpers.maybe(() => true, { | ||
probability: 0.8, | ||
}), | ||
agree_terms: !!faker.helpers.maybe(() => true, {probability: 0.8}), | ||
notice_privacy_statement: !!faker.helpers.maybe(() => true, { | ||
probability: 0.8, | ||
}), | ||
}); | ||
} | ||
|
||
return postToBackend('/account', accounts); | ||
} | ||
|
||
// Generate one login_for_account per given account | ||
export function generateLoginForAccount(accountIds, orcids) { | ||
const homeOrganisations = [null]; | ||
for (let i = 0; i < 10; i++) { | ||
homeOrganisations.push('Organisation for ' + faker.word.noun()); | ||
} | ||
const providers = ['ipd1', 'idp2', 'idp3', 'ip4']; | ||
|
||
let orcidsAdded = 0; | ||
const login_for_accounts = []; | ||
accountIds.forEach(accountId => { | ||
let firstName = faker.person.firstName(); | ||
let givenName = faker.person.lastName(); | ||
|
||
if (orcidsAdded < orcids.length) { | ||
const orcid = orcids[orcidsAdded]; | ||
orcidsAdded += 1; | ||
login_for_accounts.push({ | ||
account: accountId, | ||
name: firstName + ' ' + givenName, | ||
email: faker.internet.email({ | ||
firstName: firstName, | ||
lastName: givenName, | ||
}), | ||
sub: orcid, | ||
provider: 'orcid', | ||
home_organisation: faker.helpers.arrayElement(homeOrganisations), | ||
last_login_date: | ||
faker.helpers.maybe(() => faker.date.past({years: 3}), { | ||
probability: 0.8, | ||
}) ?? null, | ||
}); | ||
} else { | ||
login_for_accounts.push({ | ||
account: accountId, | ||
name: firstName + ' ' + givenName, | ||
email: faker.internet.email({ | ||
firstName: firstName, | ||
lastName: givenName, | ||
}), | ||
sub: faker.string.alphanumeric(30), | ||
provider: faker.helpers.arrayElement(providers), | ||
home_organisation: faker.helpers.arrayElement(homeOrganisations), | ||
last_login_date: | ||
faker.helpers.maybe(() => faker.date.past({years: 3}), { | ||
probability: 0.8, | ||
}) ?? null, | ||
}); | ||
} | ||
}); | ||
return login_for_accounts; | ||
} | ||
|
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,14 @@ | ||
import jwt from 'jsonwebtoken'; | ||
|
||
function createJWT() { | ||
const secret = process.env.PGRST_JWT_SECRET || 'reallyreallyreallyreallyverysafe'; | ||
return jwt.sign({role: 'rsd_admin'}, secret, {expiresIn: '2m'}); | ||
} | ||
|
||
export const token = createJWT(); | ||
|
||
export const headers = { | ||
'Content-Type': 'application/json', | ||
Authorization: 'bearer ' + token, | ||
Prefer: 'return=representation,resolution=ignore-duplicates', | ||
}; |
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,103 @@ | ||
import {faker} from '@faker-js/faker'; | ||
|
||
import { | ||
generateRelationsForDifferingEntities, | ||
generateUniqueCaseInsensitiveString, | ||
generateKeywordsForEntity, | ||
postToBackend, | ||
getKeywordIds | ||
} from './utils.js' | ||
import {organisationLogos,getLocalImageIds} from './images.js'; | ||
|
||
export async function generateCommunities({idsSoftware,amount = 500}){ | ||
const localOrganisationLogoIds = await getLocalImageIds(organisationLogos); | ||
const idsKeywords = await getKeywordIds() | ||
// add communities | ||
const communities = await postToBackend('/community', createCommunities(localOrganisationLogoIds,amount)) | ||
const idsCommunities = communities.map(c=>c.id) | ||
// add other data | ||
const comData = await Promise.all([ | ||
postToBackend('/keyword_for_community', generateKeywordsForEntity(idsCommunities, idsKeywords, 'community')), | ||
postToBackend('/software_for_community', generateSoftwareForCommunity(idsSoftware, idsCommunities)), | ||
generateCategories(idsCommunities) | ||
]) | ||
|
||
return idsCommunities | ||
} | ||
|
||
export function createCommunities(localOrganisationLogoIds,amount = 500) { | ||
const result = []; | ||
|
||
for (let index = 0; index < amount; index++) { | ||
const maxWords = faker.helpers.maybe(() => 5, {probability: 0.8}) ?? 31; | ||
const name = generateUniqueCaseInsensitiveString(() => | ||
('Community ' + faker.word.words(faker.number.int({max: maxWords, min: 1}))).substring(0, 200), | ||
); | ||
|
||
result.push({ | ||
slug: faker.helpers.slugify(name).toLowerCase().replaceAll(/-{2,}/g, '-').replaceAll(/-+$/g, ''), // removes double dashes and trailing dashes | ||
name: name, | ||
short_description: faker.helpers.maybe(() => faker.lorem.paragraphs(1, '\n\n'), {probability: 0.8}) ?? null, | ||
description: faker.helpers.maybe(() => faker.lorem.paragraphs(1, '\n\n'), {probability: 0.8}) ?? null, | ||
logo_id: | ||
faker.helpers.maybe(() => localOrganisationLogoIds[index % localOrganisationLogoIds.length], {probability: 0.8}) ?? | ||
null, | ||
}); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
export async function generateCategories(idsCommunities, maxDepth = 3) { | ||
const communityPromises = []; | ||
for (const commId of idsCommunities) { | ||
communityPromises.push(generateAndSaveCategoriesForCommunity(commId, maxDepth)); | ||
} | ||
communityPromises.push(generateAndSaveCategoriesForCommunity(null, maxDepth)); | ||
|
||
return await Promise.all(communityPromises); | ||
} | ||
|
||
export async function generateAndSaveCategoriesForCommunity(idCommunity, maxDepth) { | ||
return new Promise(async res => { | ||
let parentIds = [null]; | ||
for (let level = 1; level <= maxDepth; level++) { | ||
const newParentIds = []; | ||
for (const parent of parentIds) { | ||
let toGenerateCount = faker.number.int(4); | ||
if (idCommunity === null && level === 1) { | ||
toGenerateCount += 1; | ||
} | ||
for (let i = 0; i < toGenerateCount; i++) { | ||
const name = `Parent ${parent}, level ${level}, item ${i + 1}`; | ||
const shortName = `Level ${level}, item ${i + 1}`; | ||
const body = { | ||
community: idCommunity, | ||
parent: parent, | ||
short_name: shortName, | ||
name: name, | ||
}; | ||
const categories = await postToBackend('/category', body) | ||
newParentIds.push(categories[0].id) | ||
} | ||
} | ||
parentIds = newParentIds; | ||
} | ||
res(); | ||
}); | ||
} | ||
|
||
export function generateSoftwareForCommunity(idsSoftware, idsCommunities) { | ||
const result = generateRelationsForDifferingEntities(idsCommunities, idsSoftware, 'community', 'software'); | ||
|
||
const statuses = [ | ||
{weight: 1, value: 'pending'}, | ||
{weight: 8, value: 'approved'}, | ||
{weight: 1, value: 'rejected'}, | ||
]; | ||
result.forEach(entry => { | ||
entry['status'] = faker.helpers.weightedArrayElement(statuses); | ||
}); | ||
|
||
return result; | ||
} |
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
Oops, something went wrong.