fix tests
This commit is contained in:
@ -72,7 +72,7 @@ export class Subscription {
|
||||
scheduledAt?: Date | null
|
||||
|
||||
@Column('boolean')
|
||||
isPublic?: boolean | null
|
||||
isPrivate?: boolean | null
|
||||
|
||||
@Column('boolean')
|
||||
autoAddToLibrary?: boolean | null
|
||||
|
||||
@ -2703,7 +2703,7 @@ export enum SubscribeErrorCode {
|
||||
|
||||
export type SubscribeInput = {
|
||||
autoAddToLibrary?: InputMaybe<Scalars['Boolean']>;
|
||||
isPublic?: InputMaybe<Scalars['Boolean']>;
|
||||
isPrivate?: InputMaybe<Scalars['Boolean']>;
|
||||
subscriptionType?: InputMaybe<SubscriptionType>;
|
||||
url: Scalars['String'];
|
||||
};
|
||||
@ -2717,11 +2717,13 @@ export type SubscribeSuccess = {
|
||||
|
||||
export type Subscription = {
|
||||
__typename?: 'Subscription';
|
||||
autoAddToLibrary?: Maybe<Scalars['Boolean']>;
|
||||
count: Scalars['Int'];
|
||||
createdAt: Scalars['Date'];
|
||||
description?: Maybe<Scalars['String']>;
|
||||
icon?: Maybe<Scalars['String']>;
|
||||
id: Scalars['ID'];
|
||||
isPrivate?: Maybe<Scalars['Boolean']>;
|
||||
lastFetchedAt?: Maybe<Scalars['Date']>;
|
||||
name: Scalars['String'];
|
||||
newsletterEmail?: Maybe<Scalars['String']>;
|
||||
@ -3065,7 +3067,7 @@ export type UpdateSubscriptionInput = {
|
||||
autoAddToLibrary?: InputMaybe<Scalars['Boolean']>;
|
||||
description?: InputMaybe<Scalars['String']>;
|
||||
id: Scalars['ID'];
|
||||
isPublic?: InputMaybe<Scalars['Boolean']>;
|
||||
isPrivate?: InputMaybe<Scalars['Boolean']>;
|
||||
lastFetchedAt?: InputMaybe<Scalars['Date']>;
|
||||
lastFetchedChecksum?: InputMaybe<Scalars['String']>;
|
||||
name?: InputMaybe<Scalars['String']>;
|
||||
@ -5948,11 +5950,13 @@ export type SubscribeSuccessResolvers<ContextType = ResolverContext, ParentType
|
||||
};
|
||||
|
||||
export type SubscriptionResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['Subscription'] = ResolversParentTypes['Subscription']> = {
|
||||
autoAddToLibrary?: SubscriptionResolver<Maybe<ResolversTypes['Boolean']>, "autoAddToLibrary", ParentType, ContextType>;
|
||||
count?: SubscriptionResolver<ResolversTypes['Int'], "count", ParentType, ContextType>;
|
||||
createdAt?: SubscriptionResolver<ResolversTypes['Date'], "createdAt", ParentType, ContextType>;
|
||||
description?: SubscriptionResolver<Maybe<ResolversTypes['String']>, "description", ParentType, ContextType>;
|
||||
icon?: SubscriptionResolver<Maybe<ResolversTypes['String']>, "icon", ParentType, ContextType>;
|
||||
id?: SubscriptionResolver<ResolversTypes['ID'], "id", ParentType, ContextType>;
|
||||
isPrivate?: SubscriptionResolver<Maybe<ResolversTypes['Boolean']>, "isPrivate", ParentType, ContextType>;
|
||||
lastFetchedAt?: SubscriptionResolver<Maybe<ResolversTypes['Date']>, "lastFetchedAt", ParentType, ContextType>;
|
||||
name?: SubscriptionResolver<ResolversTypes['String'], "name", ParentType, ContextType>;
|
||||
newsletterEmail?: SubscriptionResolver<Maybe<ResolversTypes['String']>, "newsletterEmail", ParentType, ContextType>;
|
||||
|
||||
@ -2130,7 +2130,7 @@ enum SubscribeErrorCode {
|
||||
|
||||
input SubscribeInput {
|
||||
autoAddToLibrary: Boolean
|
||||
isPublic: Boolean
|
||||
isPrivate: Boolean
|
||||
subscriptionType: SubscriptionType
|
||||
url: String!
|
||||
}
|
||||
@ -2142,11 +2142,13 @@ type SubscribeSuccess {
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
autoAddToLibrary: Boolean
|
||||
count: Int!
|
||||
createdAt: Date!
|
||||
description: String
|
||||
icon: String
|
||||
id: ID!
|
||||
isPrivate: Boolean
|
||||
lastFetchedAt: Date
|
||||
name: String!
|
||||
newsletterEmail: String
|
||||
@ -2463,7 +2465,7 @@ input UpdateSubscriptionInput {
|
||||
autoAddToLibrary: Boolean
|
||||
description: String
|
||||
id: ID!
|
||||
isPublic: Boolean
|
||||
isPrivate: Boolean
|
||||
lastFetchedAt: Date
|
||||
lastFetchedChecksum: String
|
||||
name: String
|
||||
|
||||
@ -228,35 +228,37 @@ export const subscribeResolver = authorized<
|
||||
const feed = await parser.parseURL(input.url)
|
||||
|
||||
const results = await authTrx(async (t) => {
|
||||
await t.getRepository(Feed).upsert(
|
||||
{
|
||||
url: feed.feedUrl,
|
||||
title: feed.title,
|
||||
description: feed.description,
|
||||
image: feed.image?.url,
|
||||
},
|
||||
{
|
||||
conflictPaths: ['url'],
|
||||
skipUpdateIfNoValuesChanged: true,
|
||||
}
|
||||
)
|
||||
if (!input.isPrivate) {
|
||||
await t.getRepository(Feed).upsert(
|
||||
{
|
||||
url: feed.feedUrl,
|
||||
title: feed.title,
|
||||
description: feed.description,
|
||||
image: feed.image?.url,
|
||||
},
|
||||
{
|
||||
conflictPaths: ['url'],
|
||||
skipUpdateIfNoValuesChanged: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// limit number of rss subscriptions to 150
|
||||
const results = (await t.getRepository(Subscription).query(
|
||||
`insert into omnivore.subscriptions (name, url, description, type, user_id, icon, auto_add_to_library, is_public)
|
||||
`insert into omnivore.subscriptions (name, url, description, type, user_id, icon, auto_add_to_library, is_private)
|
||||
select $1, $2, $3, $4, $5, $6, $7, $8 from omnivore.subscriptions
|
||||
where user_id = $5 and type = 'RSS' and status = 'ACTIVE'
|
||||
having count(*) < $9
|
||||
returning *;`,
|
||||
[
|
||||
feed.title,
|
||||
input.url,
|
||||
feed.feedUrl,
|
||||
feed.description || null,
|
||||
SubscriptionType.Rss,
|
||||
uid,
|
||||
feed.image?.url || null,
|
||||
input.autoAddToLibrary ?? null,
|
||||
input.isPublic ?? null,
|
||||
input.isPrivate ?? null,
|
||||
MAX_RSS_SUBSCRIPTIONS,
|
||||
]
|
||||
)) as Subscription[]
|
||||
@ -335,7 +337,7 @@ export const updateSubscriptionResolver = authorized<
|
||||
? new Date(input.scheduledAt)
|
||||
: undefined,
|
||||
autoAddToLibrary: input.autoAddToLibrary ?? undefined,
|
||||
isPublic: input.isPublic ?? undefined,
|
||||
isPrivate: input.isPrivate ?? undefined,
|
||||
})
|
||||
|
||||
return repo.findOneByOrFail({
|
||||
|
||||
@ -1658,6 +1658,8 @@ const schema = gql`
|
||||
lastFetchedAt: Date
|
||||
createdAt: Date!
|
||||
updatedAt: Date
|
||||
isPrivate: Boolean
|
||||
autoAddToLibrary: Boolean
|
||||
}
|
||||
|
||||
enum SubscriptionStatus {
|
||||
@ -2554,7 +2556,7 @@ const schema = gql`
|
||||
input SubscribeInput {
|
||||
url: String!
|
||||
subscriptionType: SubscriptionType
|
||||
isPublic: Boolean
|
||||
isPrivate: Boolean
|
||||
autoAddToLibrary: Boolean
|
||||
}
|
||||
|
||||
@ -2566,7 +2568,7 @@ const schema = gql`
|
||||
lastFetchedChecksum: String
|
||||
status: SubscriptionStatus
|
||||
scheduledAt: Date
|
||||
isPublic: Boolean
|
||||
isPrivate: Boolean
|
||||
autoAddToLibrary: Boolean
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ import 'mocha'
|
||||
import Parser from 'rss-parser'
|
||||
import sinon from 'sinon'
|
||||
import sinonChai from 'sinon-chai'
|
||||
import { Feed } from '../../src/entity/feed'
|
||||
import { NewsletterEmail } from '../../src/entity/newsletter_email'
|
||||
import { Subscription } from '../../src/entity/subscription'
|
||||
import { User } from '../../src/entity/user'
|
||||
@ -332,7 +333,9 @@ describe('Subscriptions API', () => {
|
||||
const updatedSubscription = await getRepository(Subscription).findOneBy({
|
||||
id: subscription.id,
|
||||
})
|
||||
expect(updatedSubscription?.status).to.eql(SubscriptionStatus.Unsubscribed)
|
||||
expect(updatedSubscription?.status).to.eql(
|
||||
SubscriptionStatus.Unsubscribed
|
||||
)
|
||||
|
||||
// check if the email was sent
|
||||
expect(fake).to.have.been.calledOnceWith({
|
||||
@ -371,10 +374,15 @@ describe('Subscriptions API', () => {
|
||||
|
||||
before(async () => {
|
||||
// fake rss parser
|
||||
sinon.replace(Parser.prototype, 'parseURL', sinon.fake.resolves({
|
||||
title: 'RSS Feed',
|
||||
description: 'RSS Feed Description',
|
||||
}))
|
||||
sinon.replace(
|
||||
Parser.prototype,
|
||||
'parseURL',
|
||||
sinon.fake.resolves({
|
||||
title: 'RSS Feed',
|
||||
description: 'RSS Feed Description',
|
||||
feedUrl: url,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
after(() => {
|
||||
@ -398,6 +406,7 @@ describe('Subscriptions API', () => {
|
||||
|
||||
after(async () => {
|
||||
await deleteSubscription(existingSubscription.id)
|
||||
await getRepository(Feed).delete({ url: existingSubscription.url })
|
||||
})
|
||||
|
||||
it('returns an error', async () => {
|
||||
@ -439,11 +448,9 @@ describe('Subscriptions API', () => {
|
||||
})
|
||||
|
||||
it('creates a rss subscription', async () => {
|
||||
const res = await graphqlRequest(
|
||||
query,
|
||||
authToken,
|
||||
{ input: { url, subscriptionType } },
|
||||
).expect(200)
|
||||
const res = await graphqlRequest(query, authToken, {
|
||||
input: { url, subscriptionType },
|
||||
}).expect(200)
|
||||
expect(res.body.data.subscribe.subscriptions).to.have.lengthOf(1)
|
||||
expect(res.body.data.subscribe.subscriptions[0].id).to.be.a('string')
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE omnivore.subscriptions
|
||||
ADD COLUMN is_public boolean,
|
||||
ADD COLUMN is_private boolean,
|
||||
ADD COLUMN auto_add_to_library boolean;
|
||||
|
||||
ALTER TABLE omnivore.library_item
|
||||
@ -40,6 +40,6 @@ CREATE INDEX feed_title_idx ON omnivore.feed(title);
|
||||
|
||||
CREATE TRIGGER update_feed_modtime BEFORE UPDATE ON omnivore.feed FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column();
|
||||
|
||||
GRANT SELECT, INSERT, UPDATE ON omnivore.feed TO omnivore_user;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON omnivore.feed TO omnivore_user;
|
||||
|
||||
COMMIT;
|
||||
|
||||
@ -19,7 +19,7 @@ ALTER TABLE omnivore.library_item
|
||||
DROP COLUMN added_to_library_at;
|
||||
|
||||
ALTER TABLE omnivore.subscriptions
|
||||
DROP COLUMN is_public,
|
||||
DROP COLUMN is_private,
|
||||
DROP COLUMN auto_add_to_library;
|
||||
|
||||
COMMIT;
|
||||
|
||||
Reference in New Issue
Block a user