Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
10122ec
Added startup message
InsideAmber Jan 24, 2026
d75f16e
fix: used compatible mongodb-memory-server version for CI
InsideAmber Jan 24, 2026
5f6a8a5
Change runner from ubuntu-latest to ubuntu-20.04
InsideAmber Jan 24, 2026
c4a0d87
Update GitHub Actions runner to ubuntu-latest
InsideAmber Jan 24, 2026
c8099a6
fix: change the mongodb-memory-server version
InsideAmber Jan 24, 2026
f590ffa
fix: change the mongodb-memory-server version
InsideAmber Jan 24, 2026
2b56d68
fix: undo all the changes
InsideAmber Jan 24, 2026
1564e3d
Update MongoDB version in test setup
InsideAmber Jan 24, 2026
7b951a0
removed the version
InsideAmber Jan 24, 2026
91a0628
Merge branch 'master' into dev
InsideAmber Jan 24, 2026
47e7aa3
added compatible version
InsideAmber Jan 24, 2026
c5c7a7e
added compatible version
InsideAmber Jan 24, 2026
b1175cd
ci: Add MongoDB service and update test setup for CI compatibility
InsideAmber Jan 25, 2026
a8c4e55
Merge branch 'master' into dev
InsideAmber Jan 25, 2026
c2ea3d4
added unique signup email
InsideAmber Jan 25, 2026
d413464
added unique signup email
InsideAmber Jan 25, 2026
2781116
Added mongo setup test for ci
InsideAmber Jan 25, 2026
8465c3a
Added some unique test mail
InsideAmber Jan 25, 2026
2686cac
Added valid title for the test ticket
InsideAmber Jan 25, 2026
4d615e5
rollback the test ticket title
InsideAmber Jan 25, 2026
d2d1d6e
Added unique mail for sign in in test setup
InsideAmber Jan 25, 2026
5578af5
rollback the unique email
InsideAmber Jan 25, 2026
b59e973
Added unique email in each services
InsideAmber Jan 25, 2026
2e6a594
Added valid email to check current user
InsideAmber Jan 25, 2026
304e57a
Added alternate validation
InsideAmber Jan 25, 2026
b2942b8
Orders test fixed
InsideAmber Jan 25, 2026
f689bb7
revert the changes
InsideAmber Jan 25, 2026
e92e8c1
Added the consistent email throughout the services
InsideAmber Jan 25, 2026
960ce92
Added some debugging in orders and tickets
InsideAmber Jan 25, 2026
412b640
Add debug in orders listener test file
InsideAmber Jan 25, 2026
83b6d9b
revert the changes
InsideAmber Jan 25, 2026
e9fd3d4
Some more debugging
InsideAmber Jan 25, 2026
e1f87ee
Added som delay after creating the order
InsideAmber Jan 25, 2026
f4ad2f1
updated orders test
InsideAmber Jan 25, 2026
aa1c807
sync with master
InsideAmber Jan 25, 2026
649b16f
Added console in tickets test
InsideAmber Jan 25, 2026
cac725b
Added corrected console
InsideAmber Jan 25, 2026
95495fe
removed docker for mongo in all services
InsideAmber Jan 25, 2026
9c3f207
Merge branch 'master' into dev
InsideAmber Jan 25, 2026
16c6ca8
testing auth
InsideAmber Jan 25, 2026
39c6ba4
testing auth
InsideAmber Jan 25, 2026
8bb4fe9
Added some test console
InsideAmber Jan 25, 2026
6b6f1cd
test console
InsideAmber Jan 25, 2026
55c6184
All service test fixed
InsideAmber Jan 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests-payments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
- uses: actions/checkout@v2
- run: cd payments && npm install && npm run test:ci
- run: cd payments && npm install && npm run test:ci
2 changes: 1 addition & 1 deletion auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"start": "ts-node-dev src/index.ts",
"test": "jest --watchAll --no-cache",
"test:ci":"jest"
"test:ci": "jest"
},
"jest": {
"preset": "ts-jest",
Expand Down
1 change: 1 addition & 0 deletions auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import mongoose from 'mongoose';
import { app } from './app';

const start = async () => {
console.log('Starting...');
if (!process.env.JWT_KEY) {
throw new Error('JWT_KEY must be defined');
}
Expand Down
2 changes: 1 addition & 1 deletion auth/src/routes/__test__/current-user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ it('responds with details about the current user', async () => {
.send()
.expect(200);

expect(response.body.currentUser.email).toEqual("test@test.com");
expect(response.body.currentUser.email).toContain('@test.com');
});

it('responds with null if not authenticated', async () => {
Expand Down
2 changes: 1 addition & 1 deletion auth/src/routes/__test__/signup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ it("returns a 201 on successful signup", async () => {
return request(app)
.post("/api/users/signup")
.send({
email: "test@test.com",
email: "testsignup@test.com",
password: "password"
})
.expect(201);
Expand Down
22 changes: 15 additions & 7 deletions auth/src/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import mongoose from 'mongoose';
import request from 'supertest';
import { app } from '../app';

// jest.setTimeout(120000); // 2 minutes
jest.setTimeout(120000); // 2 minutes

declare global {
var signin: () => Promise<string[]>;
Expand All @@ -12,10 +12,18 @@ declare global {
let mongo: any;
beforeAll(async () => {
process.env.JWT_KEY = 'asdfasdf'
mongo = await MongoMemoryServer.create();
const mongoUri = mongo.getUri();

await mongoose.connect(mongoUri, {});
let mongoUri: string;

// Use mongodb-memory-server for local development
mongo = await MongoMemoryServer.create({
binary: {
version: "5.0.5"
}
});
mongoUri = mongo.getUri();


await mongoose.connect(mongoUri, {});
});


Expand All @@ -37,7 +45,7 @@ afterAll(async () => {
});

global.signin = async () => {
const email = 'test@test.com';
const email = `test-${Date.now()}-${Math.random()}@test.com`; // Unique email each time
const password = 'password';

const response = await request(app)
Expand All @@ -54,4 +62,4 @@ global.signin = async () => {
throw new Error("Failed to get cookie from response");
}
return cookie;
};
};
3 changes: 1 addition & 2 deletions orders/src/events/listeners/expiration-complete-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Message } from "node-nats-streaming";
import { queueGroupName } from "./queue-group-name";
import { Order } from "../../models/order";
import { OrderCancelledPublisher } from "../publishers/order-cancelled-publisher";
import { natsWrapper } from "../../nats-wrapper";

// Main purpose of this listener is to listen for expiration complete events
// and then update the order status to cancelled
Expand All @@ -27,7 +26,7 @@ export class ExpirationCompleteListener extends Listener<ExpirationCompleteEvent
await order.save();

// publish an event saying that the order has been cancelled
await new OrderCancelledPublisher(natsWrapper.client).publish({
await new OrderCancelledPublisher(this.client).publish({
id: order.id,
version: order.version,
ticket: {
Expand Down
2 changes: 1 addition & 1 deletion orders/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const start = async () => {
}

app.listen(3000, () => {
console.log("listening on port 3000!!!");
console.log("listening on port 3000!!");
});
};

Expand Down
18 changes: 15 additions & 3 deletions orders/src/routes/__test__/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ it('marks an order as cancelled', async () => {
});
await ticket.save();


const user = global.signin();
// make a request to create an order
const { body: order } = await request(app)
Expand All @@ -35,6 +36,7 @@ it('marks an order as cancelled', async () => {
expect(updatedOrder!.status).toEqual(OrderStatus.Cancelled);
});


it('emits a order cancelled event', async () => {
const ticket = Ticket.build({
id: new mongoose.Types.ObjectId().toHexString(),
Expand All @@ -44,12 +46,22 @@ it('emits a order cancelled event', async () => {
await ticket.save();

const user = global.signin();

console.log('Ticket ID:', ticket.id);
console.log('User cookie:', user);

// make a request to create an order
const { body: order } = await request(app)
const response = await request(app)
.post('/api/orders')
.set('Cookie', user)
.send({ ticketId: ticket.id })
.expect(201);
.send({ ticketId: ticket.id });

console.log('Response status:', response.status);
console.log('Response body:', response.body);

expect(response.status).toBe(201);

const order = response.body;

// make a request to cancel the order
await request(app)
Expand Down
43 changes: 22 additions & 21 deletions orders/src/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {MongoMemoryServer} from 'mongodb-memory-server';
import mongoose from 'mongoose';
import jwt from 'jsonwebtoken';
import { MongoMemoryServer } from "mongodb-memory-server";
import mongoose from "mongoose";
import jwt from "jsonwebtoken";

// jest.setTimeout(120000); // 2 minutes
jest.setTimeout(120000); // 2 minutes

declare global {
var signin: () => string[];
Expand All @@ -12,23 +12,25 @@ jest.mock("../nats-wrapper");

let mongo: any;
beforeAll(async () => {
process.env.JWT_KEY = 'asdfasdf'
mongo = await MongoMemoryServer.create({
binary: {
version: "5.0.5"
}
});
const mongoUri = mongo.getUri();
process.env.JWT_KEY = "asdfasdf";
let mongoUri: string;

// Use mongodb-memory-server for local development
mongo = await MongoMemoryServer.create({
binary: {
version: "5.0.5",
},
});
mongoUri = mongo.getUri();

await mongoose.connect(mongoUri, {});
});


beforeEach(async () => {
jest.clearAllMocks();
if (mongoose.connection.db) {
if (mongoose.connection.db) {
const collections = await mongoose.connection.db.collections();

for (let collection of collections) {
await collection.deleteMany({});
}
Expand All @@ -46,22 +48,21 @@ global.signin = () => {
// Build a JWT payload. {id, email}
const payload = {
id: new mongoose.Types.ObjectId().toHexString(),
email:'test@test.com'
}
email: "test@test.com",
};

// Create the JWT!
const token = jwt.sign(payload, process.env.JWT_KEY!);

// build session object {jwt: MY_JWT}
const session = { jwt: token };
const session = { jwt: token };

// Turn that session into JSON
const sessionJSON = JSON.stringify(session);

// Take JSON and encode it as base64
const base64 = Buffer.from(sessionJSON).toString('base64');

const base64 = Buffer.from(sessionJSON).toString("base64");

// return a string thats the cookie with the encoded data
return [`session=${base64}`];
};
return [`session=${base64}`];
};
2 changes: 1 addition & 1 deletion payments/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const start = async () => {
}

app.listen(3000, () => {
console.log("listening on port 3000!!");
console.log("listening on port 3000!!!");
});
};

Expand Down
50 changes: 26 additions & 24 deletions payments/src/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
import {MongoMemoryServer} from 'mongodb-memory-server';
import mongoose from 'mongoose';
import request from 'supertest';
import { app } from '../app';
import jwt from 'jsonwebtoken';
import { MongoMemoryServer } from "mongodb-memory-server";
import mongoose from "mongoose";
import request from "supertest";
import { app } from "../app";
import jwt from "jsonwebtoken";

jest.setTimeout(120000); // 2 minutes

declare global {
var signin: (id?:string) => string[];
var signin: (id?: string) => string[];
}

jest.mock("../nats-wrapper");

process.env.STRIPE_KEY = 'sk_test_mock';
process.env.STRIPE_KEY = "sk_test_mock";

let mongo: any;
beforeAll(async () => {
process.env.JWT_KEY = 'asdfasdf'
mongo = await MongoMemoryServer.create({
binary: {
version: "5.0.5"
}
});
const mongoUri = mongo.getUri();
process.env.JWT_KEY = "asdfasdf";
let mongoUri: string;

// Use mongodb-memory-server for local development
mongo = await MongoMemoryServer.create({
binary: {
version: "5.0.5",
},
});
mongoUri = mongo.getUri();


await mongoose.connect(mongoUri, {});
});


beforeEach(async () => {
jest.clearAllMocks();
if (mongoose.connection.db) {
if (mongoose.connection.db) {
const collections = await mongoose.connection.db.collections();

for (let collection of collections) {
await collection.deleteMany({});
}
Expand All @@ -46,26 +49,25 @@ afterAll(async () => {
await mongoose.connection.close();
});

global.signin = (id?:string) => {
global.signin = (id?: string) => {
// Build a JWT payload. {id, email}
const payload = {
id: id || new mongoose.Types.ObjectId().toHexString(),
email: 'test@test.com',
email: "test@test.com",
};

// Create the JWT!
const token = jwt.sign(payload, process.env.JWT_KEY!);

// build session object {jwt: MY_JWT}
const session = { jwt: token };
const session = { jwt: token };

// Turn that session into JSON
const sessionJSON = JSON.stringify(session);

// Take JSON and encode it as base64
const base64 = Buffer.from(sessionJSON).toString('base64');

const base64 = Buffer.from(sessionJSON).toString("base64");

// return a string thats the cookie with the encoded data
return [`session=${base64}`];
};
return [`session=${base64}`];
};
1 change: 1 addition & 0 deletions tickets/src/routes/__test__/new.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ it("creates a ticket with valid input", async () => {
})
.expect(201);


tickets = await Ticket.find({});
expect(tickets.length).toEqual(1);
expect(tickets[0].price).toEqual(20);
Expand Down
2 changes: 1 addition & 1 deletion tickets/src/routes/__test__/show.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ it("returns a 404 if the ticket is not found", async () => {
});

it("returns the ticket if the ticket is found", async () => {
const title = "concert";
const title = "valid title";
const price = 20;
const createResponse = await request(app)
.post("/api/tickets")
Expand Down
Loading