Skip to content

Commit

Permalink
Merge pull request #905 from Grommers00/user-883
Browse files Browse the repository at this point in the history
Fix #883 - Add a user - ready for review. Round #2.
  • Loading branch information
Grommers00 committed Mar 31, 2020
2 parents c1ae02a + 1371fe7 commit 033cdf1
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/backend/data/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const hash = require('./hash');
const urlToId = url => hash(normalizeUrl(url));

class Feed {
constructor(author, url, link, etag, lastModified) {
constructor(author, url, user, link, etag, lastModified) {
if (!url) {
throw new Error('missing url for feed');
}
Expand All @@ -24,7 +24,9 @@ class Feed {
this.id = urlToId(url);
this.author = author;
this.url = url;
this.user = user;
this.link = link;

// We may or may not have these cache values when we create a feed.
this.etag = etag === '' ? null : etag;
this.lastModified = lastModified === '' ? null : lastModified;
Expand Down Expand Up @@ -80,6 +82,7 @@ class Feed {
const feed = new Feed(
feedData.author,
feedData.url,
feedData.user,
feedData.link,
feedData.etag,
feedData.lastModified
Expand All @@ -99,8 +102,7 @@ class Feed {
if (!(data && data.id)) {
return null;
}

return new Feed(data.author, data.url, data.link, data.etag, data.lastModified);
return new Feed(data.author, data.url, data.user, data.link, data.etag, data.lastModified);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/backend/feed/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ async function getFeedInfo(feed) {
link: null,
contentType: null,
shouldDownload: true,
// We do not have user-info at this stage currently, once feeds get added it will include passport.js information here.
user: null,
};

let response;
Expand Down
2 changes: 2 additions & 0 deletions src/backend/utils/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ module.exports = {
feed.author,
'url',
feed.url,
'user',
feed.user,
'link',
feed.link,
'etag',
Expand Down
7 changes: 5 additions & 2 deletions test/feed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ const hash = require('../src/backend/data/hash');

const urlToId = url => hash(normalizeUrl(url));

describe('Fost data class tests', () => {
describe('Post data class tests', () => {
const data = {
author: 'Post Author',
url: 'https://user.feed.com/feed.rss',
user: 'user',
id: urlToId('https://user.feed.com/feed.rss'),
link: 'https://user.feed.com/',
etag: null,
lastModified: null,
};

const createFeed = () => new Feed(data.author, data.url, data.link, null, null);
const createFeed = () => new Feed(data.author, data.url, data.user, data.link, null, null);

test('Feed should be a function', () => {
expect(typeof Feed).toBe('function');
Expand Down Expand Up @@ -43,6 +44,7 @@ describe('Fost data class tests', () => {
expect(feed.url).toEqual(data.url);
expect(feed.id).toEqual(data.id);
expect(feed.link).toEqual(data.link);
expect(feed.user).toEqual(data.user);
});

test('Feed.byId() for an invalid id should return null', async () => {
Expand All @@ -57,6 +59,7 @@ describe('Fost data class tests', () => {
expect(feed.url).toEqual(data.url);
expect(feed.id).toEqual(data.id);
expect(feed.link).toEqual(data.link);
expect(feed.user).toEqual(data.user);
});

test('Feed.byId() for an invalid url should return null', async () => {
Expand Down
7 changes: 6 additions & 1 deletion test/feeds.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ describe('test /feeds/:id responses', () => {
const missingUrl = 'http://missing-url';

// an object to be added for testing purposes
const addedFeed = new Feed('foo', existingUrl, existingLink);
const addedFeed = new Feed('foo', existingUrl, 'user', existingLink);

// an object, expected to be returned by a correct query
const receivedFeed = {
author: 'foo',
url: existingUrl,
user: 'user',
link: existingLink,
id: hash(existingUrl),
etag: null,
Expand Down Expand Up @@ -73,6 +74,7 @@ describe('test POST /feeds endpoint', () => {
const feedData = {
author: 'foo',
url: 'http://telescope200.cdot.systems',
user: 'user',
};
const res = await request(app)
.post('/feeds')
Expand All @@ -88,6 +90,7 @@ describe('test POST /feeds endpoint', () => {
it('no author being sent', async () => {
const feedData = {
author: null,
user: 'user',
url: 'http://telescope200.cdot.systems',
};
const res = await request(app)
Expand All @@ -100,6 +103,7 @@ describe('test POST /feeds endpoint', () => {
it('no url being sent', async () => {
const feedData = {
author: 'foo',
user: 'user',
url: null,
};
const res = await request(app)
Expand All @@ -113,6 +117,7 @@ describe('test POST /feeds endpoint', () => {
const feedData = {
author: 'foo',
url: 'http://telescope0.cdot.systems',
user: 'user',
};
await Feed.create(feedData);
const res = await request(app)
Expand Down
2 changes: 2 additions & 0 deletions test/posts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('test /posts/:id responses', () => {
const feed1 = new Feed(
'Feed Author',
'http://feed-url.com/',
'user',
'https://feed-link.com/',
null,
null
Expand Down Expand Up @@ -118,6 +119,7 @@ describe('test /posts/:id responses', () => {
// Create a feed
const feedId = await Feed.create({
author: 'Feed Author',
user: 'user',
url: 'https://feed-url.com/',
});
const feed = await Feed.byId(feedId);
Expand Down
8 changes: 5 additions & 3 deletions test/storage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ const Feed = require('../src/backend/data/feed');
const hash = require('../src/backend/data/hash');

describe('Storage tests for feeds', () => {
const feed1 = new Feed('James Smith', 'http://seneca.co/jsmith');
const feed2 = new Feed('James Smith 2', 'http://seneca.co/jsmith/2');
const feed3 = new Feed('James Smith 2', 'http://seneca.co/jsmith/3', null, 'etag');
const feed1 = new Feed('James Smith', 'http://seneca.co/jsmith', 'user');
const feed2 = new Feed('James Smith 2', 'http://seneca.co/jsmith/2', 'user');
const feed3 = new Feed('James Smith 2', 'http://seneca.co/jsmith/3', 'user', null, 'etag');
const feed4 = new Feed(
'James Smith 2',
'http://seneca.co/jsmith/4',
'user',
'http://seneca.co/jsmith',
'etag',
'last-modified'
Expand All @@ -33,6 +34,7 @@ describe('Storage tests for feeds', () => {
expect(feed.url).toEqual(feed1.url);
expect(feed.etag).toEqual('');
expect(feed.lastModified).toEqual('');
expect(feed.user).toEqual(feed1.user);
});

it('should return expected feed count', async () => {
Expand Down
6 changes: 4 additions & 2 deletions tools/add-feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ async function add() {
log.error('Usage: add-feed --name <name of the blog author> --url <the feed of the url>');
process.exit(1);
}
const { name, url, link } = args;

const { name, url, user, link } = args;

if (!isValidUrl(url)) {
log.error('INVALID URL');
process.exit(1);
}

try {
await Feed.create({ author: name, url, link });
await Feed.create({ author: name, url, user, link });
process.exit(0);
} catch (err) {
process.exit(1);
Expand Down

0 comments on commit 033cdf1

Please sign in to comment.