Skip to content

Commit

Permalink
Update octokit version and refactor test imports; improve settings se…
Browse files Browse the repository at this point in the history
…rvice return types
  • Loading branch information
austenstone committed Jan 13, 2025
1 parent 0b39e8d commit a4912e2
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 33 deletions.
2 changes: 1 addition & 1 deletion backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"express-rate-limit": "^7.4.1",
"mongoose": "^8.8.4",
"mysql2": "^3.11.4",
"octokit": "^4.0.2",
"octokit": "4.1",
"smee-client": "^2.0.4",
"update-dotenv": "^1.1.1",
"why-is-node-running": "^3.2.1"
Expand Down
8 changes: 4 additions & 4 deletions backend/src/__tests__/services/combinedServiceTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { generateSurveys } from '../__mock__/survey-gen/runSurveyGenerator.js';
import { MockSeatsGenerator } from '../__mock__/seats-gen/mockSeatsGenerator.js';
import { MockMetricsGenerator } from '../__mock__/metrics-gen/mockGenerator.js';
import type { MockConfig, SeatsMockConfig } from '../__mock__/types.js';
import { MetricDailyResponseType } from '../../models/metrics.model.js';
import Database from '../../database.js';
import 'dotenv/config';
import seatsExample from '../__mock__/seats-gen/seatsExample.json'; type: 'json';
import fs from 'fs';

if (!process.env.MONGODB_URI) throw new Error('MONGODB_URI is not defined');
const database = new Database(process.env.MONGODB_URI);
Expand Down Expand Up @@ -132,6 +131,7 @@ async function runSeatTest() {
const queryAt = new Date();
const seats = generateExampleSeatsData();
console.log('Generated seats:', seats.length);
const seatsExample = JSON.parse(fs.readFileSync('../__mock__/seats-gen/seatsExample.json', 'utf8'));
await SeatService.insertSeats(org, queryAt, seatsExample.seats);
// const insertedSeats = await SeatService.getAllSeats(org);
// if (!insertedSeats || insertedSeats.length === 0) {
Expand All @@ -145,10 +145,10 @@ async function runSeatTest() {

async function runMetricsTest() {
console.log('Running Metrics Test...');
const exampleData: MetricDailyResponseType[] = generateExampleMetricsData();
const exampleData: any = generateExampleMetricsData(); // : MetricDailyResponseType[]
console.log('Generated metrics:', exampleData.length);
for (const metric of exampleData) {
await metricsService.insertMetrics("octodemo", [metric], null);
await metricsService.insertMetrics("octodemo", [metric]);
}

}
Expand Down
6 changes: 4 additions & 2 deletions backend/src/__tests__/services/metricsServiceStandalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ const exampleConfig: MockConfig = {
repositories: ['demo/repo1', 'demo/repo2']
};

const org = "octodemo";

function generateExampleData() {
const mockGenerator = new MockMetricsGenerator(exampleConfig);
return mockGenerator.generateMetrics();
return mockGenerator.generateMetrics(exampleConfig); // pass config?
}

if (!process.env.MONGODB_URI) throw new Error('MONGODB_URI is not defined');
Expand All @@ -98,7 +100,7 @@ async function runTest() {
console.log(JSON.stringify(exampleData, null, 2));

// Verify the insertion
const insertedMetrics = await metricsService.getMetrics("octodemo");
const insertedMetrics = await metricsService.getMetrics(org);

// Assertions
if (!insertedMetrics || insertedMetrics.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function runTest() {


//loop through each seat and if the last_activity_at is "false" print the seat object to console.
seats.seats.forEach((seat) => {
seats.seats.forEach((seat: any) => {
if (seat.last_activity_at === "false") {
console.log("a false last activity was found", seat);
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers/adoption.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request, Response } from 'express';
import SeatsService from '../services/copilot.seats.service.js';
import adoptionService from 'services/adoption.service.js';
import adoptionService from '../services/adoption.service.js';

class AdoptionController {
async getAdoptions(req: Request, res: Response): Promise<void> {
Expand Down
3 changes: 1 addition & 2 deletions backend/src/controllers/settings.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class SettingsController {
if (!settings) {
return res.status(404).json({ error: 'Settings not found' });
}
const settingsRsp = Object.fromEntries(settings.map(setting => [setting.dataValues.name, setting.dataValues.value]));
res.json(settingsRsp);
res.json(settings);
} catch (error) {
res.status(500).json(error);
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/controllers/survey.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class SurveyController {

async createSurvey(req: Request, res: Response): Promise<void> {
try {
// const Survey = mongoose.model('Survey');
// const survey = await Survey.create(req.body);
const Survey = mongoose.model('Survey');
const survey = await Survey.create(req.body);
surveyService.createSurvey(req.body);
console.log('Creating survey (controller):', survey);
res.status(201).json(survey);
Expand Down
7 changes: 3 additions & 4 deletions backend/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ class Database {
serverSelectionTimeoutMS: 30000, // Server selection timeout
});
// this.mongoose.set('debug', false);
this.mongoose.set('toJSON', (collectionName, methodName, ...methodArgs) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const msgMapper = (m: any) => {
mongoose.set('debug', (collectionName: string, methodName: string, ...methodArgs: unknown[]) => {
const msgMapper = (m: unknown) => {
return util.inspect(m, false, 10, true)
.replace(/\n/g, '').replace(/\s{2,}/g, ' ');
};
logger.debug(`\x1B[0;36mMongoose:\x1B[0m: ${collectionName}.${methodName}` + `(${methodArgs.map(msgMapper).join(', ')})`)
logger.debug(`\x1B[0;36mMongoose:\x1B[0m: ${collectionName}.${methodName}` + `(${methodArgs.map(msgMapper).join(', ')})`);
});
//logger.info('Database setup completed successfully');
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SeatsController from '../controllers/seats.controller.js';
import metricsController from '../controllers/metrics.controller.js';
import teamsController from '../controllers/teams.controller.js';
import targetValuesController from '../controllers/target-values.controller.js';
import adoptionController from 'controllers/adoption.controller.js';
import adoptionController from '../controllers/adoption.controller.js';

const router = Router();

Expand Down
6 changes: 3 additions & 3 deletions backend/src/services/copilot.seats.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import mongoose from 'mongoose';
import { MemberActivityType, MemberType } from 'models/teams.model.js';
import fs from 'fs';

type _Seat = NonNullable<Endpoints["GET /orgs/{org}/copilot/billing/seats"]["response"]["data"]["seats"]>[0];
type _Seat = any;// NonNullable<Endpoints["GET /orgs/{org}/copilot"]["response"]["data"]["seats"]>[0];

Check failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.
export interface SeatEntry extends _Seat {
plan_type: string;
plan_type: "business" | "enterprise" | "unknown";
assignee: components['schemas']['simple-user'];
}

Expand Down Expand Up @@ -170,7 +170,7 @@ class SeatsService {
precision?: 'hour' | 'day' | 'minute';
since?: string;
until?: string;
} = {}): any { // Promise<MemberDailyActivity> {
} = {}): Promise<any> { // Promise<MemberDailyActivity> {

Check failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.
console.log('getMembersActivity', params);
const Seats = mongoose.model('Seats');
// const Member = mongoose.model('Member');
Expand Down
9 changes: 5 additions & 4 deletions backend/src/services/settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ class SettingsService {
return this.settings;
}

async getAllSettings(): Promise<{ [key: string]: string; } | null> {
async getAllSettings() {
try {
const Setting = mongoose.model('Settings');
return await Setting.findOne({});
return await Setting.find<{
name: string;
value: string;
}>({});
} catch (error) {
console.error('Failed to get all settings:', error);
throw error;
Expand All @@ -63,7 +66,6 @@ class SettingsService {
async updateSetting(name: keyof SettingsType, value: string) {
try {
const Setting = mongoose.model('Settings');

const setting = await Setting.findOneAndUpdate(
{ name },
{ value },
Expand All @@ -72,7 +74,6 @@ class SettingsService {
upsert: true,
}
);

return setting.value;
} catch (error) {
console.error('Failed to update setting:', error);
Expand Down
19 changes: 12 additions & 7 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
"inlineSources": true,
"resolveJsonModule": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "**/*.spec.ts"],

"ts-node": {
"esm": true,
"experimentalSpecifiers": true
}
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"src/__tests__/**", // temp
"**/*.spec.ts"
],
"ts-node": {
"esm": true,
"experimentalSpecifiers": true
}
}

0 comments on commit a4912e2

Please sign in to comment.