Skip to content

Commit

Permalink
fix testing schema
Browse files Browse the repository at this point in the history
  • Loading branch information
gridsane committed Apr 4, 2017
1 parent 3978c0c commit 01d4b79
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/api/reddit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default class RedditAPI {
const tracks = await this.getTracks(id, {limit: 1});
return convertChannel(id, tracks.list[0].cover);
} catch (err) {
console.error(err);
return null;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/server/jobs/update-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ export default async function updateSchema(storage) {
const db = await storage.getDb();
const collection = db.collection('channels');

await collection.dropIndex('TextIndex');
try {
await collection.dropIndex('TextIndex');
} catch (err) {
await db.createCollection('channels');
}

return collection.createIndex(
{name: 'text', description: 'text', tags: 'text'},
Expand Down
5 changes: 5 additions & 0 deletions test/server/storage_test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import mongo from 'mongodb';
import updateSchema from '../../src/server/jobs/update-schema';
import Storage from '../../src/server/storage';
import {MONGO_URI_TEST} from '../../src/config';

describe('Storage @database', () => {
const storage = new Storage(MONGO_URI_TEST);

before(async () => {
await updateSchema(storage);
});

beforeEach((done) => {
mongo.connect(MONGO_URI_TEST, (err, db) => {
db.collection('channels').deleteMany({}, done);
Expand Down

0 comments on commit 01d4b79

Please sign in to comment.