add mocks

This commit is contained in:
Tykayn 2022-01-10 11:06:31 +01:00 committed by tykayn
parent a0d6163186
commit 52a0ec6284
7 changed files with 1090 additions and 646 deletions

View File

@ -26,10 +26,103 @@ npm i
ajouter un cronjob qui exécute régulièrement (une fois par jour)
```angular2html
```bash
ts-node index.ts
```
# Example de requête
Les examples sont mis dans le dossier mocks
- creation
```
entêtes:
{
"POST": {
"scheme": "http",
"host": "localhost:4000",
"filename": "/api",
"remote": {
"Adresse": "127.0.0.1:4000"
}
}
}
{
"En-têtes de la requête (2,286 Ko)": {
"headers": [
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Accept-Encoding",
"value": "gzip, deflate"
},
{
"name": "Accept-Language",
"value": "fr,en-US;q=0.7,en;q=0.3"
},
{
"name": "authorization",
"value": "Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJtb2JpbGl6b24iLCJleHAiOjE2NDE4MDg1ODIsImlhdCI6MTY0MTgwNzY4MiwiaXNzIjoibW9iaWxpem9uIiwianRpIjoiYTk5YzE3OTQtNThjZS00YmFhLWJhMTktMjcwYWJjNzFkMGI4IiwibmJmIjoxNjQxODA3NjgxLCJzdWIiOiJVc2VyOjEiLCJ0eXAiOiJhY2Nlc3MifQ.9w7JaWQo7j-xHrDspWF5HqnlRBw2U0uyUxNfYbSc6NihyRLTrKFZSMAGNnR2lgZYPO8I-SgiK043wSWau1GnNQ"
},
{
"name": "Cache-Control",
"value": "no-cache"
},
{
"name": "Connection",
"value": "keep-alive"
},
{
"name": "Content-Length",
"value": "4454"
},
{
"name": "content-type",
"value": "application/json"
},
{
"name": "Cookie",
"value": "Phpstorm-bbc0ac47=545e6b0c-6c8b-4445-b724-49644b98bd77; ph_mqkwGT0JNFqO-zX2t0mW6Tec9yooaVu7xCBlXtHnt5Y_posthog=%7B%22distinct_id%22%3A%2217c3271b31913d-00bfbf13648a128-30634644-4b9600-17c3271b31a468%22%2C%22%24device_id%22%3A%2217c3271b31913d-00bfbf13648a128-30634644-4b9600-17c3271b31a468%22%7D; BetterErrors-has-used-console=true; _session_id=eyJfcmFpbHMiOnsibWVzc2FnZSI6IklqWTNNV0ZrTVRWaVlXSm1PR1UzWkdKalpqTmlPR0k1WmpZd01qRmhObUU1SWc9PSIsImV4cCI6IjIwMjItMTEtMThUMTc6MzY6MjUuNDY0WiIsInB1ciI6ImNvb2tpZS5fc2Vzc2lvbl9pZCJ9fQ%3D%3D--dede57510dc24f4a60db7864eebd7cc14e4b957a; c1ef4f9f9c63250f85741095ba5caaee=m38cfqt2k3ulmdhvbbtk497hde; f8caea90b77b67b82dd50df996d8d229=drm4t2vb5oqa6nlj0odsmsanse; 5ae7feae4c8f8e8d33845d20924ad9ba=itfhk9eumbgthphqrgrs2gpqi2; BetterErrors-2.9.1-CSRF-Token=18e3c443-00f4-4fe1-a9a0-c65a69915fbb; _mastodon_session=K11iR4Tod4FhspHo1Bxe66Ri%2BYqvWb%2F%2BnoO9WXgbpzsmdLMM%2BV6Vso0AjUz96Tu%2BhzK2Wq8KeZxR4VBKUuFNE8v%2FSdfHX9V0cwhxDU7q%2FwDVEJsgQ8xlKiL3W0v9ab%2BPkI7tLZ7SpsJTfxdLG%2BPonKhR9zApU03Q0ep80%2Fxf6F8JUfqFAsIvBMcko2mHaK%2BU9dGcQtYAFCbijSmEegrzmV0hH57w6dKxrGONmGLNTillxvTL%2BVZagOL7xB93s31jCTIGwtp%2FwVl5GN4LO44f79s3X7kVRh74wKOC8poNyvckfMvERCxj48mnn0Vw8fIj2R341fyOmsYKFoNbeGy3Oh0yFvZxQOBKK05z8%2Bi3O%2BbkFYOYPlGGawrSRQM0cOtqq%2FPV4EZxetKDuKZsTv9og%2FvsmEJwafUekbjL2G%2BsEHf4X9js8bquVaOJH2prOWV8kgBsCH7qnggWk9T5pEjVLvRj36AbsSE627iHz8IdRp646SHKz82uO5SMEgUIsMg7dAJ8fhXIHaMvvisNNwGwkEnzNYWLSLnC3Lpxzn0%3D--cmlZi7NsmOxVoFfx--RyGe8OvwX03BezCSH9bs8g%3D%3D"
},
{
"name": "Host",
"value": "localhost:4000"
},
{
"name": "Origin",
"value": "http://localhost:4000"
},
{
"name": "Pragma",
"value": "no-cache"
},
{
"name": "Referer",
"value": "http://localhost:4000/events/create"
},
{
"name": "Sec-Fetch-Dest",
"value": "empty"
},
{
"name": "Sec-Fetch-Mode",
"value": "cors"
},
{
"name": "Sec-Fetch-Site",
"value": "same-origin"
},
{
"name": "User-Agent",
"value": "Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0"
}
]
}
}
```
---
author: tykayn

View File

@ -10,11 +10,13 @@ const parserConfig = {
// database of mobilizon
db_name: "mobilizon_dev",
db_user: "mobilizon",
db_pass: "mobilizon",
db_pass: "0eHmz99Rb2WEhPKbwGJuAU-Da04jVV36QjuOOeJDOsK_Q1w7pikqIR04WqHoZLQi",
// other configs
askAgendaDuLibre: false, // should we fetch the Agenda du libre feed ?
askAgendaDuLibre: true, // should we fetch the Agenda du libre feed ?
askOsmCal: true,
runAddQueriesToMobilizon: false,
runAddQueriesToMobilizonBDD: false,
debug: false,
runAddQueriesToMobilizonAPI: true
};
export default parserConfig;

View File

@ -40,7 +40,7 @@ const runCreationQuery = utilsTools.runCreationQuery;
console.log(' ');
const res = await utilsTools.client.query('SELECT * from events');
console.log('💾 évènements enregistrés dans mobilizon : ', res.rows.length); // Hello world!
console.log('res', res);
utilsTools.localMobilizonEventsByTitle = res.rows;
if (parserConfig.askAgendaDuLibre) {
@ -91,13 +91,26 @@ const runCreationQuery = utilsTools.runCreationQuery;
console.log('arrayOfEvents[0]', arrayOfEvents[1])
utilsTools.osmcal.doesEventExists(arrayOfEvents[1])
// arrayOfEvents.forEach((eventFound) => {
// utilsTools.osmcal.doesEventExists(eventFound);
// });
let EventsToCreate:any = [];
arrayOfEvents.forEach((eventFound:any) => {
if(!utilsTools.osmcal.doesEventExists(eventFound)){
EventsToCreate.push(eventFound);
};
});
utilsTools.createEventQueriesForApi(EventsToCreate)
});
}
if (parserConfig.runAddQueriesToMobilizon) {
if (parserConfig.runAddQueriesToMobilizonAPI) {
console.log(
' rajouter les évènements manquants par l\'API GraphQL',
);
}
if (parserConfig.runAddQueriesToMobilizonBDD) {
// @ts-ignore
console.log(
' rajouter les évènements manquants à la base mobilizon',

51
mocks/creation.json Normal file
View File

@ -0,0 +1,51 @@
{
"operationName": "createEvent",
"query": "mutation createEvent($organizerActorId: ID!, $attributedToId: ID, $title: String!, $description: String!, $beginsOn: DateTime!, $endsOn: DateTime, $status: EventStatus, $visibility: EventVisibility, $joinOptions: EventJoinOptions, $draft: Boolean, $tags: [String], $picture: MediaInput, $onlineAddress: String, $phoneAddress: String, $category: String, $physicalAddress: AddressInput, $options: EventOptionsInput, $contacts: [Contact]) {\n createEvent(\n organizerActorId: $organizerActorId\n attributedToId: $attributedToId\n title: $title\n description: $description\n beginsOn: $beginsOn\n endsOn: $endsOn\n status: $status\n visibility: $visibility\n joinOptions: $joinOptions\n draft: $draft\n tags: $tags\n picture: $picture\n onlineAddress: $onlineAddress\n phoneAddress: $phoneAddress\n category: $category\n physicalAddress: $physicalAddress\n options: $options\n contacts: $contacts\n ) {\n ...FullEvent\n __typename\n }\n}\n\nfragment FullEvent on Event {\n id\n uuid\n url\n local\n title\n description\n beginsOn\n endsOn\n status\n visibility\n joinOptions\n draft\n picture {\n id\n url\n name\n metadata {\n width\n height\n blurhash\n __typename\n }\n __typename\n }\n publishAt\n onlineAddress\n phoneAddress\n physicalAddress {\n ...AdressFragment\n __typename\n }\n organizerActor {\n avatar {\n id\n url\n __typename\n }\n preferredUsername\n domain\n name\n url\n id\n summary\n __typename\n }\n contacts {\n avatar {\n id\n url\n __typename\n }\n preferredUsername\n name\n summary\n domain\n url\n id\n __typename\n }\n attributedTo {\n avatar {\n id\n url\n __typename\n }\n preferredUsername\n name\n summary\n domain\n url\n id\n __typename\n }\n participantStats {\n going\n notApproved\n participant\n __typename\n }\n tags {\n ...TagFragment\n __typename\n }\n relatedEvents {\n id\n uuid\n title\n beginsOn\n picture {\n id\n url\n name\n metadata {\n width\n height\n blurhash\n __typename\n }\n __typename\n }\n physicalAddress {\n id\n description\n __typename\n }\n organizerActor {\n id\n avatar {\n id\n url\n __typename\n }\n preferredUsername\n domain\n name\n __typename\n }\n __typename\n }\n options {\n ...EventOptions\n __typename\n }\n metadata {\n key\n title\n value\n type\n __typename\n }\n __typename\n}\n\nfragment AdressFragment on Address {\n id\n description\n geom\n street\n locality\n postalCode\n region\n country\n type\n url\n originId\n __typename\n}\n\nfragment TagFragment on Tag {\n id\n slug\n title\n __typename\n}\n\nfragment EventOptions on EventOptions {\n maximumAttendeeCapacity\n remainingAttendeeCapacity\n showRemainingAttendeeCapacity\n anonymousParticipation\n showStartTime\n showEndTime\n offers {\n price\n priceCurrency\n url\n __typename\n }\n participationConditions {\n title\n content\n url\n __typename\n }\n attendees\n program\n commentModeration\n showParticipationPrice\n hideOrganizerWhenGroupEvent\n __typename\n}\n",
"variables": {
"attributedToId": null,
"beginsOn": "2022-01-11T09:45:00.000Z",
"contacts": [],
"description": "<p>la description</p>",
"draft": false,
"endsOn": "2022-01-11T12:00:00.000Z",
"joinOptions": "FREE",
"onlineAddress": "https://cipherbliss.com",
"options": {
"anonymousParticipation": true,
"attendees": [],
"commentModeration": "ALLOW_ALL",
"hideOrganizerWhenGroupEvent": false,
"maximumAttendeeCapacity": 200,
"offers": [],
"participationConditions": [],
"program": "",
"remainingAttendeeCapacity": 0,
"showEndTime": true,
"showParticipationPrice": false,
"showRemainingAttendeeCapacity": false,
"showStartTime": true
},
"organizerActorId": "3",
"phoneAddress": "",
"physicalAddress": {
"country": "France",
"description": "3 Rue du Temple",
"geom": "2.3525187;48.857539",
"id": null,
"locality": "Paris",
"originId": "nominatim:700449153",
"postalCode": "75004",
"region": "Île-de-France",
"street": "3 Rue du Temple",
"type": "house",
"url": null
},
"status": "CONFIRMED",
"tags": [
"machin",
"chose"
],
"title": "blah titre",
"visibility": "PUBLIC"
}
}

View File

@ -0,0 +1,38 @@
{
"operationName": "createEvent",
"query": "mutation createEvent($organizerActorId: ID!, $attributedToId: ID, $title: String!, $description: String!, $beginsOn: DateTime!, $endsOn: DateTime, $status: EventStatus, $visibility: EventVisibility, $joinOptions: EventJoinOptions, $draft: Boolean, $tags: [String], $picture: MediaInput, $onlineAddress: String, $phoneAddress: String, $category: String, $physicalAddress: AddressInput, $options: EventOptionsInput, $contacts: [Contact]) {\n createEvent(\n organizerActorId: $organizerActorId\n attributedToId: $attributedToId\n title: $title\n description: $description\n beginsOn: $beginsOn\n endsOn: $endsOn\n status: $status\n visibility: $visibility\n joinOptions: $joinOptions\n draft: $draft\n tags: $tags\n picture: $picture\n onlineAddress: $onlineAddress\n phoneAddress: $phoneAddress\n category: $category\n physicalAddress: $physicalAddress\n options: $options\n contacts: $contacts\n ) {\n ...FullEvent\n __typename\n }\n}\n\nfragment FullEvent on Event {\n id\n uuid\n url\n local\n title\n description\n beginsOn\n endsOn\n status\n visibility\n joinOptions\n draft\n picture {\n id\n url\n name\n metadata {\n width\n height\n blurhash\n __typename\n }\n __typename\n }\n publishAt\n onlineAddress\n phoneAddress\n physicalAddress {\n ...AdressFragment\n __typename\n }\n organizerActor {\n avatar {\n id\n url\n __typename\n }\n preferredUsername\n domain\n name\n url\n id\n summary\n __typename\n }\n contacts {\n avatar {\n id\n url\n __typename\n }\n preferredUsername\n name\n summary\n domain\n url\n id\n __typename\n }\n attributedTo {\n avatar {\n id\n url\n __typename\n }\n preferredUsername\n name\n summary\n domain\n url\n id\n __typename\n }\n participantStats {\n going\n notApproved\n participant\n __typename\n }\n tags {\n ...TagFragment\n __typename\n }\n relatedEvents {\n id\n uuid\n title\n beginsOn\n picture {\n id\n url\n name\n metadata {\n width\n height\n blurhash\n __typename\n }\n __typename\n }\n physicalAddress {\n id\n description\n __typename\n }\n organizerActor {\n id\n avatar {\n id\n url\n __typename\n }\n preferredUsername\n domain\n name\n __typename\n }\n __typename\n }\n options {\n ...EventOptions\n __typename\n }\n metadata {\n key\n title\n value\n type\n __typename\n }\n __typename\n}\n\nfragment AdressFragment on Address {\n id\n description\n geom\n street\n locality\n postalCode\n region\n country\n type\n url\n originId\n __typename\n}\n\nfragment TagFragment on Tag {\n id\n slug\n title\n __typename\n}\n\nfragment EventOptions on EventOptions {\n maximumAttendeeCapacity\n remainingAttendeeCapacity\n showRemainingAttendeeCapacity\n anonymousParticipation\n showStartTime\n showEndTime\n offers {\n price\n priceCurrency\n url\n __typename\n }\n participationConditions {\n title\n content\n url\n __typename\n }\n attendees\n program\n commentModeration\n showParticipationPrice\n hideOrganizerWhenGroupEvent\n __typename\n}\n",
"variables": {
"attributedToId": null,
"beginsOn": "2022-01-11T09:45:00.000Z",
"contacts": [],
"description": "<p>la description</p>",
"draft": false,
"endsOn": "2022-01-11T12:00:00.000Z",
"joinOptions": "FREE",
"onlineAddress": "https://cipherbliss.com",
"options": {
"anonymousParticipation": true,
"attendees": [],
"commentModeration": "ALLOW_ALL",
"hideOrganizerWhenGroupEvent": false,
"maximumAttendeeCapacity": 200,
"offers": [],
"participationConditions": [],
"program": "",
"remainingAttendeeCapacity": 0,
"showEndTime": true,
"showParticipationPrice": false,
"showRemainingAttendeeCapacity": false,
"showStartTime": true
},
"organizerActorId": "3",
"phoneAddress": "",
"status": "CONFIRMED",
"tags": [
"machin",
"chose"
],
"title": "blah titre",
"visibility": "PUBLIC"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -17,8 +17,7 @@ class utils {
makeQuery = () => {
this.createEventQueries = `INSERT INTO events(title, description, organizer_actor_id, inserted_at, updated_at,
uuid, url, status, category, options, participants_stats,
begins_on, ends_on)
VALUES ${this.agendadulibre.queryToAdd} ${this.osmcal.queryToAdd};`;
begins_on, ends_on) VALUES ${this.agendadulibre.queryToAdd} ${this.osmcal.queryToAdd};`;
this.writeFile("event_creation_query.psql", this.createEventQueries, "psql");
}
runCreationQuery = async () => {
@ -115,7 +114,7 @@ class utils {
return event.name;
//+ ' '+ event.location.short
},
doesEventExists: (event: any) => {
doesEventExists: (event: any) : boolean => {
const eventAlreadyExists =
-1 !== this.localMobilizonEventsByTitle.indexOf(this.osmcal.getTitle(event));
if (!eventAlreadyExists) {
@ -124,6 +123,7 @@ class utils {
}
this.osmcal.addQuery(event);
}
return eventAlreadyExists;
},
addQuery: (event: any) => {
@ -219,6 +219,15 @@ class utils {
database: parserConfig.db_name,
});
}
createEventQueriesForApi(EventsToCreate: any[]) {
if(EventsToCreate.length){
console.log('we will create events', EventsToCreate.length);
}else{
console.log('no events to create');
}
}
}
export default utils;