Skip to content

Commit

Permalink
fix: only query previously published items if saving is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Sep 6, 2020
1 parent c3994dd commit 902d452
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"ava": {
"environmentVariables": {
"MONGODB_URL": "mongodb://localhost:27017/test",
"TEST_MONGODB_URL": "mongodb://localhost:27017/test",
"NODE_ENV": "test"
},
"verbose": true
Expand Down
7 changes: 3 additions & 4 deletions packages/endpoint-media/controllers/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ export const queryController = publication => {
switch (query.q) {
case 'source': {
// Return previously uploaded media
const items = await publication.media
.find()
.map(media => media.properties)
.toArray();
const items = publication.media ?
await publication.media.find().map(media => media.properties).toArray() :
[];
return response.json({
items: queryList(items, {filter, limit, offset})
});
Expand Down
7 changes: 3 additions & 4 deletions packages/endpoint-micropub/controllers/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ export const queryController = publication => {
}

// Return microformats for previously published posts
const items = await publication.posts
.find()
.map(post => post.mf2)
.toArray();
const items = publication.posts ?
await publication.posts.find().map(post => post.mf2).toArray() :
[];
return response.json({
items: queryList(items, {filter, limit, offset})
});
Expand Down
4 changes: 2 additions & 2 deletions packages/indiekit/tests/lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {mongodbConfig} from '../../config/mongodb.js';
import {Cache} from '../../lib/cache.js';

test.beforeEach(async t => {
const database = await mongodbConfig;
const database = await mongodbConfig(process.env.TEST_MONGODB_URL);
const collection = await database.collection('cache');

t.context = {
Expand All @@ -15,7 +15,7 @@ test.beforeEach(async t => {
});

test.afterEach.always(async () => {
const database = await mongodbConfig;
const database = await mongodbConfig(process.env.TEST_MONGODB_URL);
await database.dropDatabase();
});

Expand Down
4 changes: 2 additions & 2 deletions packages/indiekit/tests/lib/publication.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../../lib/publication.js';

test.beforeEach(async t => {
const database = await mongodbConfig;
const database = await mongodbConfig(process.env.TEST_MONGODB_URL);
const collection = await database.collection('cache');

t.context = await {
Expand All @@ -28,7 +28,7 @@ test.beforeEach(async t => {
});

test.afterEach.always(async () => {
const database = await mongodbConfig;
const database = await mongodbConfig(process.env.TEST_MONGODB_URL);
await database.dropDatabase();
});

Expand Down

0 comments on commit 902d452

Please sign in to comment.