Skip to content

Commit bb2fbf5

Browse files
committed
fix: bad graphql query and add extra test
1 parent 765e935 commit bb2fbf5

3 files changed

Lines changed: 63 additions & 18 deletions

File tree

apps/backend/src/datasources/postgres/ExperimentDataSource.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ export default class PostgresExperimentDataSource
577577
//print all arguments
578578

579579
const query = database('experiments')
580-
.select(['*', database.raw('count(*) OVER() AS full_count')])
580+
.select(['experiments.*', database.raw('count(*) OVER() AS full_count')])
581581
.join(
582582
'proposals',
583583
'proposals.proposal_pk',
@@ -587,24 +587,29 @@ export default class PostgresExperimentDataSource
587587

588588
// Add instrument scientist filtering if provided
589589
if (filter?.instrumentScientistUserId) {
590+
const instrumentScientistUserId = filter.instrumentScientistUserId;
591+
590592
query
591-
.leftJoin(
592-
'instrument_has_scientists',
593-
'experiments.instrument_id',
594-
'instrument_has_scientists.instrument_id'
595-
)
593+
.leftJoin('instrument_has_scientists', function () {
594+
this.on(
595+
'experiments.instrument_id',
596+
'=',
597+
'instrument_has_scientists.instrument_id'
598+
).andOnVal(
599+
'instrument_has_scientists.user_id',
600+
'=',
601+
instrumentScientistUserId
602+
);
603+
})
596604
.join(
597605
'instruments',
598606
'experiments.instrument_id',
599607
'instruments.instrument_id'
600608
)
601609
.where(function () {
602-
this.where(
603-
'instrument_has_scientists.user_id',
604-
filter!.instrumentScientistUserId
605-
).orWhere(
610+
this.whereNotNull('instrument_has_scientists.user_id').orWhere(
606611
'instruments.manager_user_id',
607-
filter!.instrumentScientistUserId
612+
instrumentScientistUserId
608613
);
609614
});
610615
}

apps/backend/src/datasources/postgres/InstrumentDataSource.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -820,15 +820,16 @@ export default class PostgresInstrumentDataSource
820820
await database
821821
.count({ count: '*' })
822822
.from('instruments as i')
823-
.leftJoin('instrument_has_scientists as ihs', {
824-
'i.instrument_id': 'ihs.instrument_id',
823+
.leftJoin('instrument_has_scientists as ihs', function () {
824+
this.on('i.instrument_id', '=', 'ihs.instrument_id').andOnVal(
825+
'ihs.user_id',
826+
'=',
827+
userId
828+
);
825829
})
826830
.where('i.instrument_id', instrumentId)
827831
.andWhere(function () {
828-
this.where('ihs.user_id', userId).orWhere(
829-
'i.manager_user_id',
830-
userId
831-
);
832+
this.whereNotNull('ihs.user_id').orWhere('i.manager_user_id', userId);
832833
})
833834
.first();
834835

apps/e2e/cypress/e2e/instruments.cy.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,10 +1886,11 @@ context('Instrument tests', () => {
18861886
});
18871887
});
18881888

1889-
describe.only('Instrument contact visibility tests', () => {
1889+
describe('Instrument contact visibility tests', () => {
18901890
let contactOnlyInstrumentId: number;
18911891
let scientistInstrumentId: number;
18921892
let createdProposalPk: number;
1893+
let createdScientistProposalPk: number;
18931894

18941895
const contactOnlyInstrument = {
18951896
name: faker.word.words(2),
@@ -1966,6 +1967,30 @@ context('Instrument tests', () => {
19661967
}
19671968
});
19681969

1970+
//create a proposal and assign it to the instrument where scientist2 is a scientist
1971+
cy.createProposal({ callId: initialDBData.call.id }).then((result) => {
1972+
if (result.createProposal) {
1973+
createdScientistProposalPk = result.createProposal.primaryKey;
1974+
1975+
cy.updateProposal({
1976+
proposalPk: createdScientistProposalPk,
1977+
title: proposal2.title,
1978+
abstract: proposal2.abstract,
1979+
});
1980+
1981+
cy.assignProposalsToInstruments({
1982+
proposalPks: [createdScientistProposalPk],
1983+
instrumentIds: [scientistInstrumentId],
1984+
});
1985+
1986+
cy.updateTechnicalReviewAssignee({
1987+
proposalPks: [createdScientistProposalPk],
1988+
userId: scientist2.id,
1989+
instrumentId: scientistInstrumentId,
1990+
});
1991+
}
1992+
});
1993+
19691994
cy.login(scientist2);
19701995
cy.visit('/');
19711996
});
@@ -2002,6 +2027,20 @@ context('Instrument tests', () => {
20022027
cy.contains(proposal1.title).should('exist');
20032028
});
20042029

2030+
it('Instrument scientist should see proposals when filtering by their scientist instrument', () => {
2031+
cy.contains('Proposals');
2032+
2033+
selectAllProposalsFilterStatus();
2034+
2035+
cy.finishedLoading();
2036+
2037+
cy.get('[data-cy="instrument-filter"]').click();
2038+
cy.get('[role="listbox"]').contains(scientistInstrument.name).click();
2039+
cy.finishedLoading();
2040+
2041+
cy.contains(proposal2.title).should('exist');
2042+
});
2043+
20052044
it('Instrument contact should see their instrument on the instruments page', () => {
20062045
cy.visit('/Instruments');
20072046

0 commit comments

Comments
 (0)