This directory contains scripts to test various functionalities of the Demia API. The main script, testAll.js
, simulates the full testing flow by making a series of API calls.
The constants.js
file contains base information required for running the example scripts.
These variables can be modified using a .env
file. See the .env.example
for the .
Below is an example of the configuration with generic arguments:
const baseUrl = 'https://api.demia.net';
const username = 'your_username';
const password = 'your_password';
// Project Details (Only change these if you want to test an alternative
// project from the Demo Project)
const auth_identifier = 'project_auth_identifier';
const announcement = 'project_announcement_address';
const site_id = 'project_site_id';
const msg_address = 'placeholder_message_address'; // You can leave this one alone
module.exports = { baseUrl, username, password, auth_identifier, announcement, site_id, msg_address };
To run the tests, xecute the testAll.js
script:
npm install
npm run start
The testAll.js
script performs the following sequence of API calls:
-
Login
- Function:
login()
- Description: Logs in to get credentials (access token and user ID).
- Function:
-
Request Identity Creation
- Function:
requestIdentity(credentials)
- Description: Requests the creation of a new identity using the provided credentials.
- Function:
-
Add New Stream or Create Site
- Function:
createSite(newStreamRequest)
oraddNewStream(newStreamRequest)
- Description: Depending on the
createNew
flag, either creates a new site or adds a new stream.
- Function:
-
Send Data to the Site
- Function:
dataTransmission(newStreamRequest.project.id, credentials)
- Description: Sends data to the newly created site (if
createNew
is true).
- Function:
-
Fetch Profile Data
- Function:
profileData(credentials)
- Description: Fetches profile data using the provided credentials.
- Function:
-
Fetch Subscriptions Data
- Function:
subscriptionsData(credentials)
- Description: Fetches subscriptions data using the provided credentials.
- Function:
-
Fetch Identity Document Request
- Function:
identityDocument(did)
- Description: Fetches the identity document request using the DID.
- Function:
-
Post Guardian Registration
- Function:
guardianRegistration(credentials)
- Description: Posts the Guardian registration using the provided credentials.
- Function:
-
Fetch Guardian Identity Request
- Function:
guardianIdentity(credentials)
- Description: Fetches the Guardian identity request using the provided credentials.
- Function:
-
Post Guardian Report
- Function:
postGuardianReport(credentials)
- Description: Posts the Guardian report using the provided credentials.
- Function:
-
Fetch Site Sensors Request
- Function:
siteSensorsRequest(credentials)
- Description: Fetches the site sensors request using the provided credentials.
- Function:
-
Fetch Site Analytics Request
- Function:
siteAnalyticsRequest(credentials)
- Description: Fetches the site analytics request using the provided credentials.
- Function:
Additionally, there are 2 service functions that are available for setting up default values
-
Prepare New Stream Request
- Function:
createNewSiteRequest(did, auth_identifier, announcement, site_id, credentials)
- Description: Prepares the request for creating a new stream.
- Function:
-
Generate Mock Sensor Data
- Function:
makeMockSensorData()
- Description: Generates mock sensor data with random values for testing purposes.
- Function: