Skip to content

Commit 7279088

Browse files
authored
fixes getodk#745: exclude unpublished datasets from the count (getodk#762)
1 parent ad061f6 commit 7279088

File tree

2 files changed

+50
-33
lines changed

2 files changed

+50
-33
lines changed

lib/model/query/projects.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ ${extend|| sql`
9494
on field_keys."projectId"=projects.id
9595
left outer join
9696
(select "projectId", count("id")::integer as "datasets" from datasets
97+
where "publishedAt" is not null
9798
group by "projectId") as dataset_counts
9899
on dataset_counts."projectId"=projects.id`}
99100
${(actorId == null) ? sql`` : sql`

test/integration/api/projects.js

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -287,40 +287,56 @@ describe('api: /projects', () => {
287287
body.should.be.a.Project();
288288
}))));
289289

290-
it('should return extended metadata if requested', testService((service) =>
291-
service.login('alice', (asAlice) =>
292-
asAlice.get('/v1/projects/1')
293-
.set('X-Extended-Metadata', 'true')
290+
it('should return extended metadata if requested', testService(async (service) => {
291+
const asAlice = await service.login('alice');
292+
293+
await asAlice.get('/v1/projects/1')
294+
.set('X-Extended-Metadata', 'true')
295+
.expect(200)
296+
.then(({ body }) => {
297+
body.should.be.an.ExtendedProject();
298+
body.forms.should.equal(2);
299+
body.datasets.should.equal(0);
300+
should.not.exist(body.lastSubmission);
301+
});
302+
303+
await Promise.all([
304+
asAlice.post('/v1/projects/1/forms/simple/submissions')
305+
.send(testData.instances.simple.one)
306+
.set('Content-Type', 'application/xml')
307+
.expect(200),
308+
asAlice.post('/v1/projects/1/forms/simple/submissions')
309+
.send(testData.instances.simple.two)
310+
.set('Content-Type', 'application/xml')
294311
.expect(200)
295-
.then(({ body }) => {
296-
body.should.be.an.ExtendedProject();
297-
body.forms.should.equal(2);
298-
body.datasets.should.equal(0);
299-
should.not.exist(body.lastSubmission);
300-
})
301-
.then(() => Promise.all([
302-
asAlice.post('/v1/projects/1/forms/simple/submissions')
303-
.send(testData.instances.simple.one)
304-
.set('Content-Type', 'application/xml')
305-
.expect(200),
306-
asAlice.post('/v1/projects/1/forms/simple/submissions')
307-
.send(testData.instances.simple.two)
308-
.set('Content-Type', 'application/xml')
309-
.expect(200)
310-
]))
311-
.then(() => asAlice.post('/v1/projects/1/forms?publish=true')
312-
.send(testData.forms.simpleEntity)
313-
.set('Content-Type', 'application/xml')
314-
.expect(200))
315-
.then(() => asAlice.get('/v1/projects/1')
316-
.set('X-Extended-Metadata', 'true')
317-
.expect(200)
318-
.then(({ body }) => {
319-
body.should.be.an.ExtendedProject();
320-
body.forms.should.equal(3);
321-
body.datasets.should.equal(1);
322-
body.lastSubmission.should.be.a.recentIsoDate();
323-
})))));
312+
]);
313+
314+
await asAlice.post('/v1/projects/1/forms')
315+
.send(testData.forms.simpleEntity)
316+
.set('Content-Type', 'application/xml')
317+
.expect(200);
318+
319+
await asAlice.get('/v1/projects/1')
320+
.set('X-Extended-Metadata', 'true')
321+
.expect(200)
322+
.then(({ body }) => {
323+
body.should.be.an.ExtendedProject();
324+
body.forms.should.equal(3);
325+
body.datasets.should.equal(0); // Form that created dataset is not published yet
326+
body.lastSubmission.should.be.a.recentIsoDate();
327+
});
328+
329+
await asAlice.post('/v1/projects/1/forms/simpleEntity/draft/publish')
330+
.expect(200);
331+
332+
await asAlice.get('/v1/projects/1')
333+
.set('X-Extended-Metadata', 'true')
334+
.expect(200)
335+
.then(({ body }) => {
336+
body.datasets.should.equal(1);
337+
});
338+
339+
}));
324340

325341
it('should not count deleted app users', testService((service) =>
326342
service.login('alice', (asAlice) =>

0 commit comments

Comments
 (0)