Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Jul 15, 2024
1 parent f2cef87 commit 21e08b5
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 309 deletions.
2 changes: 2 additions & 0 deletions packages/altair-api/jest.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// declare global {
// }
declare namespace jest {
interface Matchers<R> {
toBeUser(): R;
Expand Down
10 changes: 5 additions & 5 deletions packages/altair-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"@nestjs/schematics": "^10.1.2",
"@nestjs/testing": "^10.3.10",
"@types/bcrypt": "^5.0.2",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/express": "^4.17.13",
"@types/jest": "^28.1.8",
"@types/newrelic": "^9.14.4",
"@types/node": "^20.14.10",
"@types/passport-google-oauth": "^1.0.45",
Expand All @@ -53,15 +53,15 @@
"eslint": "^9.6.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"jest": "^29.4.1",
"passport-custom": "^1.1.1",
"pino-pretty": "^11.2.1",
"prettier": "^3.3.2",
"prisma": "^5.16.2",
"source-map-support": "^0.5.21",
"supertest": "^7.0.0",
"sync-dotenv": "^2.7.0",
"ts-jest": "^29.2.2",
"ts-jest": "^29.0.5",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
Expand All @@ -70,7 +70,7 @@
"license": "UNLICENSED",
"private": true,
"scripts": {
"build": "nest build",
"build": "tsc --noEmit && nest build",
"env": "sync-dotenv",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
Expand Down
9 changes: 6 additions & 3 deletions packages/altair-api/src/auth/user/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '../mocks/stripe-service.mock';
import Stripe from 'stripe';
import { PRO_PLAN_ID } from '@altairgraphql/db';
// import { beforeAll, beforeEach, describe, expect, it, jest } from '@jest/globals';

describe('UserService', () => {
let service: UserService;
Expand Down Expand Up @@ -250,9 +251,11 @@ describe('UserService', () => {
jest
.spyOn(stripeService, 'getPlanInfoByRole')
.mockResolvedValueOnce(mockPlanInfo());
jest.spyOn(stripeService, 'createCheckoutSession').mockResolvedValueOnce({
url: urlMock,
} as Stripe.Response<Stripe.Checkout.Session>);
jest
.spyOn(stripeService, 'createSubscriptionCheckoutSession')
.mockResolvedValueOnce({
url: urlMock,
} as Stripe.Response<Stripe.Checkout.Session>);

// WHEN
const url = await service.getProPlanUrl(userMock.id);
Expand Down
5 changes: 4 additions & 1 deletion packages/altair-api/src/credit/credit.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CreditController } from './credit.controller';
import { CreditService } from './credit.service';
import { PrismaService } from 'nestjs-prisma';
import { UserService } from 'src/auth/user/user.service';
import { StripeService } from 'src/stripe/stripe.service';

describe('CreditController', () => {
let controller: CreditController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [CreditController],
providers: [CreditService],
providers: [CreditService, PrismaService, UserService, StripeService],
}).compile();

controller = module.get<CreditController>(CreditController);
Expand Down
2 changes: 1 addition & 1 deletion packages/altair-api/src/credit/credit.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard';
import { Request } from 'express';
import { BuyDto } from './dto/buy.dto';

@Controller('credit')
@Controller('credits')
@ApiTags('Credits')
@UseGuards(JwtAuthGuard)
export class CreditController {
Expand Down
5 changes: 4 additions & 1 deletion packages/altair-api/src/credit/credit.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Module } from '@nestjs/common';
import { CreditService } from './credit.service';
import { CreditController } from './credit.controller';
import { AuthModule } from 'src/auth/auth.module';
import { StripeService } from 'src/stripe/stripe.service';

@Module({
imports: [AuthModule],
controllers: [CreditController],
providers: [CreditService],
providers: [CreditService, StripeService],
})
export class CreditModule {}
5 changes: 4 additions & 1 deletion packages/altair-api/src/credit/credit.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CreditService } from './credit.service';
import { PrismaService } from 'nestjs-prisma';
import { UserService } from 'src/auth/user/user.service';
import { StripeService } from 'src/stripe/stripe.service';

describe('CreditService', () => {
let service: CreditService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [CreditService],
providers: [CreditService, PrismaService, UserService, StripeService],
}).compile();

service = module.get<CreditService>(CreditService);
Expand Down
3 changes: 2 additions & 1 deletion packages/altair-api/src/credit/credit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import {
MONTHLY_CREDIT_REFILL,
PRO_PLAN_ID,
} from '@altairgraphql/db';
import { BadRequestException, Injectable } from '@nestjs/common';
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
import { Cron, CronExpression } from '@nestjs/schedule';
import { PrismaService } from 'nestjs-prisma';
import { UserService } from 'src/auth/user/user.service';
import { StripeService } from 'src/stripe/stripe.service';

@Injectable()
export class CreditService {
private readonly logger = new Logger(CreditService.name);
constructor(
private readonly prisma: PrismaService,
private readonly userService: UserService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class StripeWebhookController {
const creditInfo = await this.stripeService.getCreditInfo();
const purchasedCreditsItem = checkoutSession.line_items?.data.find(
(item) => {
item.price?.product === creditInfo.id;
return item.price?.product === creditInfo.id;
}
);
if (purchasedCreditsItem) {
Expand Down
2 changes: 2 additions & 0 deletions packages/altair-api/src/stripe/stripe.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export class StripeService {
return this.stripe.checkout.sessions.create({
...this.commonCheckoutSessionParams(stripeCustomerId, priceId, quantity),
mode: 'payment',
success_url: `https://altairgraphql.dev/checkout_success?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `https://altairgraphql.dev/checkout_cancel?session_id={CHECKOUT_SESSION_ID}`,
});
}

Expand Down
30 changes: 5 additions & 25 deletions packages/altair-api/test/custom-matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,10 @@ function toBePlanConfig(planConfig: any) {
);
if (!check.pass) return check;

check = typeCheck(
'PlanConfig.maxQueryCount',
planConfig?.maxQueryCount,
'number'
);
check = typeCheck('PlanConfig.maxQueryCount', planConfig?.maxQueryCount, 'number');
if (!check.pass) return check;

check = typeCheck(
'PlanConfig.maxTeamCount',
planConfig?.maxTeamCount,
'number'
);
check = typeCheck('PlanConfig.maxTeamCount', planConfig?.maxTeamCount, 'number');
if (!check.pass) return check;

check = typeCheck(
Expand Down Expand Up @@ -142,11 +134,7 @@ function toBePlan(plan: any) {
check = typeCheck('Plan.maxTeamsCount', plan?.maxTeamsCount, 'number');
if (!check.pass) return check;

check = typeCheck(
'Plan.maxTeamMembersCount',
plan?.maxTeamMembersCount,
'number'
);
check = typeCheck('Plan.maxTeamMembersCount', plan?.maxTeamMembersCount, 'number');
if (!check.pass) return check;

check = typeCheck('Plan.canUpgradePro', plan?.canUpgradePro, 'boolean');
Expand All @@ -162,18 +150,10 @@ function toBeUserStats(stats: any) {
let check = typeCheck('UserStats.queries.own', stats?.queries?.own, 'number');
if (!check.pass) return check;

check = typeCheck(
'UserStats.queries.access',
stats?.queries?.access,
'number'
);
check = typeCheck('UserStats.queries.access', stats?.queries?.access, 'number');
if (!check.pass) return check;

check = typeCheck(
'UserStats.collections.own',
stats?.collections?.own,
'number'
);
check = typeCheck('UserStats.collections.own', stats?.collections?.own, 'number');
if (!check.pass) return check;

check = typeCheck(
Expand Down
2 changes: 2 additions & 0 deletions packages/altair-api/test/providers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EventEmitter2 } from '@nestjs/event-emitter';
import { PrismaService } from 'nestjs-prisma';
import { UserService } from 'src/auth/user/user.service';
import { CreditService } from 'src/credit/credit.service';
import { QueriesService } from 'src/queries/queries.service';
import { QueryCollectionsService } from 'src/query-collections/query-collections.service';
import { StripeService } from 'src/stripe/stripe.service';
Expand All @@ -14,4 +15,5 @@ export const testProviders = [
StripeService,
TeamsService,
QueryCollectionsService,
CreditService,
];
2 changes: 1 addition & 1 deletion packages/altair-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"curlup": "1.0.0",
"deepmerge": "4.2.2",
"dexie": "3.2.3",
"express": "4.17.1",
"express": "^4.19.2",
"file-dialog": "0.0.8",
"file-saver": "2.0.2",
"fuse.js": "6.4.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/altair-electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"electron-updater": "^4.6.1",
"electron-util": "^0.12.1",
"electron-window-state": "^5.0.3",
"express": "^4.18.1",
"express": "^4.19.2",
"get-port": "5.1.1",
"mime-types": "^2.1.29",
"uuid": "^9.0.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/altair-express-middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"bugs": "https://github.com/altair-graphql/altair/issues",
"dependencies": {
"altair-static": "^7.2.4",
"express": "^4.16.2"
"express": "^4.19.2"
},
"devDependencies": {
"@types/express": "^4.17.21",
"@types/express": "^4.17.13",
"@types/node": "^14.14.41",
"eslint-config-altair": "^7.2.4",
"nodemon": "^2.0.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-plugin-altair-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"altair-express-middleware": "^7.2.4"
},
"devDependencies": {
"@types/express": "^4.17.21",
"express": "^4.18.2",
"@types/express": "^4.17.13",
"express": "^4.19.2",
"typescript": "5.2.2"
},
"funding": {
Expand Down
4 changes: 2 additions & 2 deletions test-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"compression": "^1.7.4",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"express": "^4.18.2",
"express": "^4.19.2",
"graphql": "^16.6.0",
"graphql-sse": "^2.1.3",
"graphql-subscriptions": "^2.0.0",
Expand All @@ -33,7 +33,7 @@
},
"devDependencies": {
"@types/compression": "^1.7.0",
"@types/express": "^4.17.21",
"@types/express": "^4.17.13",
"@types/graphql": "^14.2.0",
"@types/graphql-upload": "^16.0.7",
"@types/lodash": "^4.14.123",
Expand Down
Loading

0 comments on commit 21e08b5

Please sign in to comment.