Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MONGO_DB_URI=mongodb+srv://username:password@orgname-zmpox.mongodb.net/databasename
TEST_DB=mongodb+srv://username:password@orgname-zmpox.mongodb.net/databasename
MONGO_DB_URI=mongodb+srv://username:password@orgname-xxxxx.mongodb.net/databasename
TEST_DB=mongodb+srv://username:password@orgname-xxxxx.mongodb.net/databasename
GoogleClientSecret=
HashString=
AllowUrl={"urls": ["http://localhost:9000", "https://localhost:9000", "http://localhost:7000", "https://localhost:7000"]}
Expand Down
4 changes: 2 additions & 2 deletions 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 package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "webjamsocketserver",
"description": "Uses latest version of socketcluster-server",
"version": "3.0.9",
"version": "3.0.10",
"license": "MIT",
"type": "module",
"main": "build/src/index.js",
Expand Down
3 changes: 1 addition & 2 deletions src/AgController/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,12 @@ class AgController {
if (gig && gig.datetime && gig.city && gig.usState && gig.venue) {
await utils.handleGig('createDocs', gig, 'gigCreated', this.gigController, this.server);
} else throw new Error('Invalid create gig data');
if (receiver.done) break;
} catch (e) {
const eMessage = (e as Error).message;
debug(eMessage);
client.socket.transmit('socketError', { newGig: eMessage });// send error back to client
break;
}
/* istanbul ignore else */if (receiver.done) break;
}
})();
}
Expand Down
56 changes: 55 additions & 1 deletion test/AgController/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,19 @@ const aStub:any = {
}),
};

const realHandleGig = utils.handleGig;
const realRemoveGig = utils.removeGig;

describe('AgControler', () => {
afterEach(() => { vi.unstubAllGlobals(); });
afterEach(() => {
vi.unstubAllGlobals();
// Several tests replace these shared utils exports with vi.fn() stubs
// (e.g. line ~483) without restoring them, which otherwise leaks into
// later tests (like the #246 regression test) that need the real
// implementation and silently breaks their assertions.
utils.handleGig = realHandleGig;
utils.removeGig = realRemoveGig;
});
let r, clientStub:any = {
id: '123',
listener: () => ({ createConsumer: () => ({ next: () => Promise.resolve({ done: true, value: '1000' }) }) }),
Expand Down Expand Up @@ -500,6 +511,49 @@ describe('AgControler', () => {
agController.newGig(cStub, 'newGig');
expect(utils.handleGig).not.toHaveBeenCalled();
});
it('keeps handling newGig on the same socket after an earlier newGig errored (#246)', async () => {
const agController = new AgController(aStub);
agController.clients = ['123'];
agController.gigController.createDocs = vi.fn(() => Promise.resolve([]));
agController.verifyAdminWrite = vi.fn(() => Promise.resolve());
const transmit = vi.fn();
let call = 0;
const cStub:any = {
socket: {
id: '123',
listener: () => ({ createConsumer: () => ({ next: () => Promise.resolve({ done: true, value: '1000' }) }) }),
transmit,
receiver: () => ({
createConsumer: () => ({
next: () => {
call += 1;
// First newGig on this socket: invalid gig data -> throws, must NOT break the loop.
if (call === 1) {
return Promise.resolve({
value: { token: 'token', gig: { venue: 'venue' } },
done: false,
});
}
// Second newGig on the SAME socket/consumer: valid data -> must still be handled.
return Promise.resolve({
value: {
token: 'token',
gig: {
venue: 'venue', datetime: new Date(), city: 'city', usState: 'state',
},
},
done: true,
});
},
}),
}),
},
};
agController.newGig(cStub, 'newGig');
await delay(1000);
expect(transmit).toHaveBeenCalledWith('socketError', { newGig: 'Invalid create gig data' });
expect(agController.gigController.createDocs).toHaveBeenCalled();
});
it('process the newImage message from client', async () => {
const agController = new AgController(aStub);
agController.clients = ['123'];
Expand Down