+ const topicResults = await manager._publishTopics(dbCtx, data, requestId);
+ assert.strictEqual(topicResults.length, 1);
+ assert.strictEqual(topicResults[0].warn.length, 0, 'unexpected warnings length');
+ assert.strictEqual(topicResults[0].err.length, 1, 'unexpected errors length');
+ assert.strictEqual(topicResults[0].topicId, undefined, 'unexpected topic id');
+ });
+ it('no topics', async function() {
+ Object.assign(data, testData.validPublishRootData);
+ delete data.topic;
+ const topicResults = await manager._publishTopics(dbCtx, data, requestId);
+ assert.strictEqual(topicResults.length, 0);
+ });
+ it('multiple valid topics', async function () {
+ manager.db.topicGetByUrl.resolves({
+ id: 222,
+ });
+ Object.assign(data, testData.validPublishRootData);
+ data.url = ['https://example.com/first', 'https://example.com/second'];
+ data.topic = ['https://example.com/third'];
+ const topicResults = await manager._publishTopics(dbCtx, data, requestId);
+ assert.strictEqual(topicResults.length, 3);
+ assert.strictEqual(topicResults[0].warn.length, 0, 'unexpected warnings length');
+ assert.strictEqual(topicResults[0].err.length, 0, 'unexpected errors length');
+ assert.strictEqual(topicResults[0].topicId, 222, 'unexpected topic id');
+ assert.strictEqual(topicResults[1].warn.length, 0, 'unexpected warnings length');
+ assert.strictEqual(topicResults[1].err.length, 0, 'unexpected errors length');
+ assert.strictEqual(topicResults[1].topicId, 222, 'unexpected topic id');
+ assert.strictEqual(topicResults[2].warn.length, 0, 'unexpected warnings length');
+ assert.strictEqual(topicResults[2].err.length, 0, 'unexpected errors length');
+ assert.strictEqual(topicResults[2].topicId, 222, 'unexpected topic id');
+ });
+ it('mix of valid and invalid topics', async function () {
+ manager.db.topicGetByUrl.onCall(1).resolves().resolves({
+ id: 222,
+ });
+ Object.assign(data, testData.validPublishRootData);
+ data.url = ['https://example.com/first', 'not a url'];
+ data.topic = ['https://example.com/third'];
+ const topicResults = await manager._publishTopics(dbCtx, data, requestId);
+ assert.strictEqual(topicResults.length, 3);
+ assert.strictEqual(topicResults[0].warn.length, 0, 'unexpected warnings length');
+ assert.strictEqual(topicResults[0].err.length, 0, 'unexpected errors length');
+ assert.strictEqual(topicResults[0].topicId, 222, 'unexpected topic id');
+ assert.strictEqual(topicResults[1].warn.length, 0, 'unexpected warnings length');
+ assert.strictEqual(topicResults[1].err.length, 1, 'unexpected errors length');
+ assert.strictEqual(topicResults[1].topicId, undefined, 'unexpected topic id');
+ assert.strictEqual(topicResults[2].warn.length, 0, 'unexpected warnings length');
+ assert.strictEqual(topicResults[2].err.length, 0, 'unexpected errors length');
+ assert.strictEqual(topicResults[2].topicId, 222, 'unexpected topic id');
+ });
+ }); // _publishTopics
+
+ describe('_publishRequest', function () {
+ let dbCtx, data, res, ctx;
+ beforeEach(function () {
+ dbCtx = {};
+ data = {};
+ res = {
+ end: sinon.stub(),
+ };
+ ctx = {};
+ });
+ it('requires a topic', async function () {
+ try {
+ await manager._publishRequest(dbCtx, data, res, ctx);
+ assert.fail(noExpectedException);
+ } catch (e) {
+ assert(e instanceof Errors.ResponseError);
+ }
+ });
+ it('processes one topic', async function() {
+ manager.db.topicGetByUrl.resolves({
+ id: 222,
+ });
+ Object.assign(data, testData.validPublishRootData);
+ manager.db.topicFetchRequested.resolves();
+ await manager._publishRequest(dbCtx, data, res, ctx);
+ assert(manager.db.topicFetchRequested.called);
+ assert.strictEqual(res.statusCode, 202);
+ assert(res.end.called);