Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/services/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,20 @@ class Feed {
return;
}

const { network, meta: { account } } = feeds[0];
const { network, network_id: accountId, meta: { account } } = feeds[0];

await storage.feeds().remove(data);

// @TODO realize it later, need to refactor totally
if (!data.keep_data && network === 'twitter') {
await storage
.twitterStatuses()
.remove({ account });
if (network === 'twitter') {
const accountFeed = await storage
.feeds()
.getByNetworkId(network, accountId);

if (!data.keep_data && accountFeed === undefined) {
await storage
.twitterStatuses()
.remove({ account });
}
}

try {
Expand Down
35 changes: 35 additions & 0 deletions test/suites/01.twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ describe('twitter', function testSuite() {
{ id: '2533316504', username: 'v_aminev' },
],
},
register2: {
internal: 'test2@test.ru',
network: 'twitter',
accounts: [
{ username: 'evgenypoyarkov' },
],
},
list: {
filter: {
internal: 'test@test.ru',
Expand All @@ -49,6 +56,11 @@ describe('twitter', function testSuite() {
network: 'twitter',
},

remove2: {
internal: 'test2@test.ru',
network: 'twitter',
},

registerFail: {
internal: 'test@test.ru',
network: 'twitter',
Expand Down Expand Up @@ -136,6 +148,11 @@ describe('twitter', function testSuite() {
.publishAndWait(uri.register, payload.register, { timeout: 15000 });
});

it('should register feed with the same account', async () => {
await service.amqp
.publishAndWait(uri.register, payload.register2, { timeout: 15000 });
});

it('should return newly registered feed', async () => {
const body = await service.amqp
.publishAndWait(uri.list, payload.list);
Expand Down Expand Up @@ -207,6 +224,24 @@ describe('twitter', function testSuite() {

it('remove feed', async () => {
await service.amqp.publishAndWait(uri.remove, payload.remove);

const data = await service
.knex('statuses')
.where({ account: payload.register2.accounts[0].username })
.first();

assert(data);
});

it('remove last feed with cleaning up of statuses', async () => {
await service.amqp.publishAndWait(uri.remove, payload.remove2);

const data = await service
.knex('statuses')
.where({ account: payload.register2.accounts[0].username })
.first();

assert(data === undefined);
});

it('should register with case insensitive', async () => {
Expand Down