-
Notifications
You must be signed in to change notification settings - Fork 976
Add tests #6483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ar2rsawseen
wants to merge
18
commits into
next
Choose a base branch
from
ar2rsawseen/next
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add tests #6483
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9c9be57
Open API Swagger docs
ar2rsawseen d3175d6
Update open api specs
ar2rsawseen 702a444
update open api specs
ar2rsawseen 7224d23
Improve alerts tests
ar2rsawseen 9d2ca7c
Improve alerts tests
ar2rsawseen 998e9ee
Add verification of cleanup
ar2rsawseen 5fa22a4
API fixes
ar2rsawseen 02035a4
Merge branch 'ar2rsawseen/master' into ar2rsawseen/next
ar2rsawseen 2c8e68e
Add dashboards tests
ar2rsawseen 02f190c
Update alerts tests
ar2rsawseen 05e7ba2
Adding dashboard tests
ar2rsawseen 7045ea5
Add crashes
ar2rsawseen 5742c28
Potential fix for code scanning alert no. 1313: Shell command built f…
ar2rsawseen 919db94
More docs and tests
ar2rsawseen 77375e9
Add hooks tests
ar2rsawseen 3f6b76f
Add more plugins
ar2rsawseen 49baab8
Add more docs
ar2rsawseen afefaaf
Merge branch 'next' into ar2rsawseen/next
ar2rsawseen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,136 @@ | ||
/** | ||
* Script to check statistics for Adjust data in Countly. | ||
* | ||
* This script checks: | ||
* 1. Number of documents in the adjust collection for the specified app_id | ||
* 2. Number of users in app_users{APP_ID} collection with custom.adjust_id | ||
* 3. Number of adjust_install events in the drill collection | ||
* | ||
* Location: | ||
* Place this script in the `bin/scripts` directory of your Countly installation. | ||
* | ||
* Usage: | ||
* 1. Replace the `APP_ID` variable with the desired app's ID. | ||
* 2. Run the script using Node.js: | ||
* ``` | ||
* node /var/countly/bin/scripts/adjust_stats.js | ||
* ``` | ||
*/ | ||
|
||
// Define the APP_ID variable | ||
const APP_ID = '5ab0c3ef92938d0e61cf77f4'; | ||
|
||
const plugins = require('../../plugins/pluginManager.js'); | ||
|
||
(async() => { | ||
console.log(`Checking Adjust statistics for APP_ID: ${APP_ID}`); | ||
|
||
try { | ||
// Connect to countly database | ||
const db = await plugins.dbConnection("countly"); | ||
|
||
// Connect to countly_drill database | ||
const drillDb = await plugins.dbConnection("countly_drill"); | ||
|
||
console.log('Connected to databases successfully.'); | ||
|
||
// 1. Check how many documents are in adjust collection for this app_id | ||
console.log('\n--- Checking adjust collection ---'); | ||
|
||
// Define date range for filtering (July 17-22, 2025) | ||
const startDate = new Date('2025-07-17T00:00:00.000Z'); | ||
const endDate = new Date('2025-07-22T23:59:59.999Z'); | ||
console.log(`Date range filter: ${startDate.toISOString()} to ${endDate.toISOString()}`); | ||
|
||
const adjustQuery = { | ||
app_id: APP_ID, | ||
cd: { | ||
$gte: startDate, | ||
$lte: endDate | ||
} | ||
}; | ||
|
||
const adjustCount = await db.collection('adjust').countDocuments(adjustQuery); | ||
console.log(`Documents in adjust collection for app_id ${APP_ID} (${startDate.toDateString()} - ${endDate.toDateString()}): ${adjustCount}`); | ||
|
||
// 1a. Check unique amount of adjust_id values in adjust collection | ||
const uniqueAdjustIds = await db.collection('adjust').distinct('adjust_id', adjustQuery); | ||
console.log(`Unique adjust_id values in adjust collection for app_id ${APP_ID} (${startDate.toDateString()} - ${endDate.toDateString()}): ${uniqueAdjustIds.length}`); | ||
|
||
// 1b. Breakdown by event property in adjust collection | ||
console.log('\n--- Event breakdown in adjust collection ---'); | ||
const eventBreakdown = await db.collection('adjust').aggregate([ | ||
{ $match: adjustQuery }, | ||
{ $group: { _id: "$event", count: { $sum: 1 } } }, | ||
{ $sort: { count: -1 } } | ||
]).toArray(); | ||
|
||
console.log('Event breakdown:'); | ||
eventBreakdown.forEach(item => { | ||
console.log(` ${item._id}: ${item.count}`); | ||
}); | ||
|
||
// 2. Check how many users in app_users{APP_ID} collection have custom.adjust_id value | ||
console.log('\n--- Checking app_users collection ---'); | ||
const appUsersCollection = 'app_users' + APP_ID; | ||
|
||
// Use the same date range but convert to seconds for fac field | ||
const appUsersQuery = { | ||
'custom.adjust_id': { $exists: true }, | ||
fac: { | ||
$gte: Math.floor(startDate.getTime() / 1000), | ||
$lte: Math.floor(endDate.getTime() / 1000) | ||
} | ||
}; | ||
|
||
const usersWithAdjustId = await db.collection(appUsersCollection).countDocuments(appUsersQuery); | ||
console.log(`Users with custom.adjust_id in ${appUsersCollection} (${startDate.toDateString()} - ${endDate.toDateString()}): ${usersWithAdjustId}`); | ||
|
||
// 2a. Check unique custom.adjust_id values in app_users collection | ||
const uniqueUserAdjustIds = await db.collection(appUsersCollection).distinct('custom.adjust_id', appUsersQuery); | ||
console.log(`Unique custom.adjust_id values in ${appUsersCollection} (${startDate.toDateString()} - ${endDate.toDateString()}): ${uniqueUserAdjustIds.length}`); | ||
|
||
// 3. Check how many adjust_install events are in drill collection | ||
console.log('\n--- Checking drill collection for adjust_install events ---'); | ||
const drillCollectionName = 'drill_events'; | ||
console.log(`Drill collection name: ${drillCollectionName}`); | ||
|
||
// Use the same date range but convert to milliseconds for ts field | ||
const drillQuery = { | ||
"a": APP_ID, | ||
"e": "adjust_install", | ||
ts: { | ||
$gte: startDate.getTime(), | ||
$lte: endDate.getTime() | ||
} | ||
}; | ||
|
||
const adjustInstallEvents = await drillDb.collection(drillCollectionName).countDocuments(drillQuery); | ||
console.log(`adjust_install events in drill collection (${startDate.toDateString()} - ${endDate.toDateString()}): ${adjustInstallEvents}`); | ||
|
||
// 3a. Check unique custom.adjust_id values in drill collection | ||
const uniqueDrillAdjustIds = await drillDb.collection(drillCollectionName).distinct('custom.adjust_id', drillQuery); | ||
console.log(`Unique custom.adjust_id values in drill collection (${startDate.toDateString()} - ${endDate.toDateString()}): ${uniqueDrillAdjustIds.length}`); | ||
|
||
// Summary | ||
console.log('\n--- SUMMARY ---'); | ||
console.log(`APP_ID: ${APP_ID}`); | ||
console.log(`Date range: ${startDate.toDateString()} - ${endDate.toDateString()}`); | ||
console.log(`Adjust collection documents: ${adjustCount}`); | ||
console.log(`Unique adjust_id values: ${uniqueAdjustIds.length}`); | ||
console.log(`Users with adjust_id: ${usersWithAdjustId}`); | ||
console.log(`Unique custom.adjust_id values in app_users: ${uniqueUserAdjustIds.length}`); | ||
console.log(`adjust_install events in drill collection: ${adjustInstallEvents}`); | ||
console.log(`Unique custom.adjust_id values in drill collection: ${uniqueDrillAdjustIds.length}`); | ||
|
||
console.log('\nStatistics check completed.'); | ||
|
||
} | ||
catch (error) { | ||
console.error('Error during statistics check:', error); | ||
} | ||
finally { | ||
console.log('Terminating the process...'); | ||
process.exit(0); | ||
} | ||
})(); |
This file contains hidden or 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,36 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* This script runs the API documentation generation process: | ||
* 1. Merge all OpenAPI specs into one file | ||
* 2. Generate Swagger UI HTML documentation | ||
*/ | ||
|
||
const { execSync } = require('child_process'); | ||
const path = require('path'); | ||
|
||
console.log('🚀 Starting API documentation generation process...'); | ||
|
||
// Paths to the scripts | ||
const scriptsDir = __dirname; | ||
const mergeScript = path.join(scriptsDir, 'merge-openapi.js'); | ||
const swaggerScript = path.join(scriptsDir, 'generate-swagger-ui.js'); | ||
|
||
try { | ||
// Step 1: Merge OpenAPI specs | ||
console.log('\n📑 Step 1: Merging OpenAPI specifications...'); | ||
execSync(`node ${mergeScript}`, { stdio: 'inherit' }); | ||
|
||
// Step 2: Generate Swagger UI documentation | ||
console.log('\n📙 Step 2: Generating Swagger UI documentation...'); | ||
execSync(`node ${swaggerScript}`, { stdio: 'inherit' }); | ||
|
||
|
||
console.log('\n✅ API documentation generation completed successfully!'); | ||
console.log('📊 Documentation is available in the doc/api directory:'); | ||
console.log(' - Swagger UI: doc/api/swagger-ui-api.html'); | ||
|
||
} | ||
catch (error) { | ||
console.error('\n❌ Error during API documentation generation:', error.message); | ||
process.exit(1); | ||
} |
This file contains hidden or 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,124 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* This script generates HTML documentation using Swagger UI from the merged OpenAPI specification. | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Configuration | ||
const outputDir = path.join(__dirname, '../../doc/api'); | ||
const mergedSpecPath = path.join(outputDir, 'openapi-merged.json'); | ||
const outputHtmlPath = path.join(outputDir, 'index.html'); | ||
|
||
// Ensure the merged spec exists | ||
if (!fs.existsSync(mergedSpecPath)) { | ||
console.error(`Merged OpenAPI spec not found at ${mergedSpecPath}`); | ||
console.error('Please run merge-openapi.js first'); | ||
process.exit(1); | ||
} | ||
|
||
console.log('Generating Swagger UI HTML documentation...'); | ||
|
||
// Create a simple HTML file with Swagger UI | ||
const swaggerUiHtml = ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Countly API Documentation</title> | ||
<link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@5/swagger-ui.css"> | ||
<link rel="icon" type="image/png" href="https://countly.com/images/favicon.png" sizes="32x32" /> | ||
<style> | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; | ||
} | ||
#swagger-ui { | ||
max-width: 1460px; | ||
margin: 0 auto; | ||
} | ||
.topbar { | ||
background-color: #0166D6 !important; | ||
padding: 10px 0; | ||
text-align: center; | ||
} | ||
.topbar-wrapper img { | ||
content: url('https://countly.com/images/logo.svg'); | ||
height: 40px; | ||
} | ||
.swagger-ui .info .title { | ||
color: #0166D6; | ||
} | ||
.swagger-ui .opblock.opblock-get .opblock-summary { | ||
border-color: #0166D6; | ||
} | ||
.swagger-ui .opblock.opblock-get .opblock-summary-method { | ||
background: #0166D6; | ||
} | ||
.swagger-ui .btn.execute { | ||
background-color: #0166D6; | ||
color: #fff; | ||
border-color: #0166D6; | ||
} | ||
.swagger-ui .btn.authorize { | ||
color: #0166D6; | ||
border-color: #0166D6; | ||
} | ||
.swagger-ui .opblock.opblock-post { | ||
background: rgba(1, 102, 214, 0.05); | ||
border-color: #0166D6; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="swagger-ui"></div> | ||
<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js"></script> | ||
<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-standalone-preset.js"></script> | ||
<script> | ||
window.onload = function() { | ||
const ui = SwaggerUIBundle({ | ||
url: "./openapi-merged.json", | ||
dom_id: '#swagger-ui', | ||
deepLinking: true, | ||
presets: [ | ||
SwaggerUIBundle.presets.apis, | ||
SwaggerUIStandalonePreset | ||
], | ||
plugins: [ | ||
SwaggerUIBundle.plugins.DownloadUrl | ||
], | ||
layout: "StandaloneLayout", | ||
tagsSorter: 'alpha', | ||
docExpansion: 'list', | ||
defaultModelsExpandDepth: 1, | ||
defaultModelExpandDepth: 1, | ||
filter: true, | ||
supportedSubmitMethods: ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'], | ||
validatorUrl: null | ||
}); | ||
window.ui = ui; | ||
}; | ||
</script> | ||
</body> | ||
</html> | ||
`; | ||
|
||
try { | ||
fs.writeFileSync(outputHtmlPath, swaggerUiHtml); | ||
|
||
// Also create a copy with the swagger-ui-api.html name for backward compatibility | ||
fs.writeFileSync(path.join(outputDir, 'swagger-ui-api.html'), swaggerUiHtml); | ||
|
||
console.log(`Successfully generated Swagger UI documentation at ${outputHtmlPath}`); | ||
console.log(`Also created a copy at ${path.join(outputDir, 'swagger-ui-api.html')} for compatibility`); | ||
} | ||
catch (error) { | ||
console.error('Failed to generate Swagger UI documentation:', error.message); | ||
process.exit(1); | ||
} | ||
|
||
console.log('Swagger UI documentation generation completed successfully!'); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.