Skip to content

Commit 1e74461

Browse files
authored
fix: update the publishAt value if it is null (getodk#778)
1 parent f2766f6 commit 1e74461

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/model/query/datasets.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ const _insertDatasetDef = (dataset, acteeId, withDsDefsCTE, publish) => sql`
6565
DO NOTHING
6666
RETURNING *
6767
),
68+
${publish ? sql`
69+
update_ds AS (
70+
UPDATE datasets SET "publishedAt" = clock_timestamp()
71+
WHERE name = ${dataset.name} AND "projectId" = ${dataset.projectId} AND "publishedAt" IS NULL
72+
),
73+
` : sql``}
6874
ds AS (
6975
SELECT *, 'created' "action" FROM ds_ins
7076
UNION ALL

test/integration/api/datasets.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,33 @@ describe('datasets and entities', () => {
13191319
body.message.should.be.eql('The entity definition within the form is invalid. Multiple Form Fields cannot be saved to a single Dataset Property.');
13201320
}));
13211321
}));
1322+
1323+
it('should publish dataset when any dataset creating form is published', testService(async (service) => {
1324+
const alice = await service.login('alice');
1325+
1326+
await alice.post('/v1/projects/1/forms')
1327+
.send(testData.forms.simpleEntity)
1328+
.set('Content-Type', 'application/xml')
1329+
.expect(200);
1330+
1331+
await alice.post('/v1/projects/1/forms?publish=true')
1332+
.send(testData.forms.simpleEntity.replace(/simpleEntity/g, 'simpleEntity2'))
1333+
.set('Content-Type', 'application/xml')
1334+
.expect(200);
1335+
1336+
await alice.get('/v1/projects/1/datasets')
1337+
.expect(200)
1338+
.then(({ body }) => {
1339+
body[0].name.should.be.eql('people');
1340+
});
1341+
1342+
await alice.get('/v1/projects/1/datasets/people')
1343+
.expect(200)
1344+
.then(({ body }) => {
1345+
body.name.should.be.eql('people');
1346+
});
1347+
1348+
}));
13221349
});
13231350

13241351
describe('dataset audit logging at /projects/:id/forms POST', () => {

0 commit comments

Comments
 (0)