From cef534ed53e4518fe0acf581bfe880788d42fc36 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 26 Dec 2018 10:36:24 +0100 Subject: Add user notification base code --- .../tests/api/check-params/user-notifications.ts | 249 +++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 server/tests/api/check-params/user-notifications.ts (limited to 'server/tests/api/check-params/user-notifications.ts') diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts new file mode 100644 index 000000000..3ae36ddb3 --- /dev/null +++ b/server/tests/api/check-params/user-notifications.ts @@ -0,0 +1,249 @@ +/* tslint:disable:no-unused-expression */ + +import 'mocha' +import * as io from 'socket.io-client' + +import { + flushTests, + immutableAssign, + killallServers, + makeGetRequest, + makePostBodyRequest, + makePutBodyRequest, + runServer, + ServerInfo, + setAccessTokensToServers, + wait +} from '../../../../shared/utils' +import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination +} from '../../../../shared/utils/requests/check-api-params' +import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users' + +describe('Test user notifications API validators', function () { + let server: ServerInfo + + // --------------------------------------------------------------- + + before(async function () { + this.timeout(30000) + + await flushTests() + + server = await runServer(1) + + await setAccessTokensToServers([ server ]) + }) + + describe('When listing my notifications', function () { + const path = '/api/v1/users/me/notifications' + + it('Should fail with a bad start pagination', async function () { + await checkBadStartPagination(server.url, path, server.accessToken) + }) + + it('Should fail with a bad count pagination', async function () { + await checkBadCountPagination(server.url, path, server.accessToken) + }) + + it('Should fail with an incorrect sort', async function () { + await checkBadSortPagination(server.url, path, server.accessToken) + }) + + it('Should fail with a non authenticated user', async function () { + await makeGetRequest({ + url: server.url, + path, + statusCodeExpected: 401 + }) + }) + + it('Should succeed with the correct parameters', async function () { + await makeGetRequest({ + url: server.url, + path, + token: server.accessToken, + statusCodeExpected: 200 + }) + }) + }) + + describe('When marking as read my notifications', function () { + const path = '/api/v1/users/me/notifications/read' + + it('Should fail with wrong ids parameters', async function () { + await makePostBodyRequest({ + url: server.url, + path, + fields: { + ids: [ 'hello' ] + }, + token: server.accessToken, + statusCodeExpected: 400 + }) + + await makePostBodyRequest({ + url: server.url, + path, + fields: { + ids: 5 + }, + token: server.accessToken, + statusCodeExpected: 400 + }) + }) + + it('Should fail with a non authenticated user', async function () { + await makePostBodyRequest({ + url: server.url, + path, + fields: { + ids: [ 5 ] + }, + statusCodeExpected: 401 + }) + }) + + it('Should succeed with the correct parameters', async function () { + await makePostBodyRequest({ + url: server.url, + path, + fields: { + ids: [ 5 ] + }, + token: server.accessToken, + statusCodeExpected: 204 + }) + }) + }) + + describe('When updating my notification settings', function () { + const path = '/api/v1/users/me/notification-settings' + const correctFields: UserNotificationSetting = { + newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION, + newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION, + videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION, + blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION + } + + it('Should fail with missing fields', async function () { + await makePutBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields: { newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION }, + statusCodeExpected: 400 + }) + }) + + it('Should fail with incorrect field values', async function () { + { + const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 15 }) + + await makePutBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields, + statusCodeExpected: 400 + }) + } + + { + const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 'toto' }) + + await makePutBodyRequest({ + url: server.url, + path, + fields, + token: server.accessToken, + statusCodeExpected: 400 + }) + } + }) + + it('Should fail with a non authenticated user', async function () { + await makePutBodyRequest({ + url: server.url, + path, + fields: correctFields, + statusCodeExpected: 401 + }) + }) + + it('Should succeed with the correct parameters', async function () { + await makePutBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields: correctFields, + statusCodeExpected: 204 + }) + }) + }) + + describe('When connecting to my notification socket', function () { + it('Should fail with no token', function (next) { + const socket = io('http://localhost:9001/user-notifications', { reconnection: false }) + + socket.on('error', () => { + socket.removeListener('error', this) + socket.disconnect() + next() + }) + + socket.on('connect', () => { + socket.disconnect() + next(new Error('Connected with a missing token.')) + }) + }) + + it('Should fail with an invalid token', function (next) { + const socket = io('http://localhost:9001/user-notifications', { + query: { accessToken: 'bad_access_token' }, + reconnection: false + }) + + socket.on('error', () => { + socket.removeListener('error', this) + socket.disconnect() + next() + }) + + socket.on('connect', () => { + socket.disconnect() + next(new Error('Connected with an invalid token.')) + }) + }) + + it('Should success with the correct token', function (next) { + const socket = io('http://localhost:9001/user-notifications', { + query: { accessToken: server.accessToken }, + reconnection: false + }) + + const errorListener = socket.on('error', err => { + next(new Error('Error in connection: ' + err)) + }) + + socket.on('connect', async () => { + socket.removeListener('error', errorListener) + socket.disconnect() + + await wait(500) + next() + }) + }) + }) + + after(async function () { + killallServers([ server ]) + + // Keep the logs if the test failed + if (this['ok']) { + await flushTests() + } + }) +}) -- cgit v1.2.3 From dc13348070d808d0ba3feb56a435b835c2e7e791 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 2 Jan 2019 16:37:43 +0100 Subject: Add import finished and video published notifs --- server/tests/api/check-params/user-notifications.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'server/tests/api/check-params/user-notifications.ts') diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts index 3ae36ddb3..4f21f7b95 100644 --- a/server/tests/api/check-params/user-notifications.ts +++ b/server/tests/api/check-params/user-notifications.ts @@ -52,6 +52,18 @@ describe('Test user notifications API validators', function () { await checkBadSortPagination(server.url, path, server.accessToken) }) + it('Should fail with an incorrect unread parameter', async function () { + await makeGetRequest({ + url: server.url, + path, + query: { + unread: 'toto' + }, + token: server.accessToken, + statusCodeExpected: 200 + }) + }) + it('Should fail with a non authenticated user', async function () { await makeGetRequest({ url: server.url, @@ -125,7 +137,9 @@ describe('Test user notifications API validators', function () { newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION, newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION, videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION, - blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION + blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION, + myVideoImportFinished: UserNotificationSettingValue.WEB_NOTIFICATION, + myVideoPublished: UserNotificationSettingValue.WEB_NOTIFICATION } it('Should fail with missing fields', async function () { -- cgit v1.2.3 From f7cc67b455a12ccae9b0ea16876d166720364357 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 4 Jan 2019 08:56:20 +0100 Subject: Add new follow, mention and user registered notifs --- server/tests/api/check-params/user-notifications.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'server/tests/api/check-params/user-notifications.ts') diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts index 4f21f7b95..635f5c9a3 100644 --- a/server/tests/api/check-params/user-notifications.ts +++ b/server/tests/api/check-params/user-notifications.ts @@ -139,7 +139,10 @@ describe('Test user notifications API validators', function () { videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION, blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION, myVideoImportFinished: UserNotificationSettingValue.WEB_NOTIFICATION, - myVideoPublished: UserNotificationSettingValue.WEB_NOTIFICATION + myVideoPublished: UserNotificationSettingValue.WEB_NOTIFICATION, + commentMention: UserNotificationSettingValue.WEB_NOTIFICATION, + newFollow: UserNotificationSettingValue.WEB_NOTIFICATION, + newUserRegistration: UserNotificationSettingValue.WEB_NOTIFICATION } it('Should fail with missing fields', async function () { -- cgit v1.2.3 From 2f1548fda32c3ba9e53913270394eedfacd55986 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 8 Jan 2019 11:26:41 +0100 Subject: Add notifications in the client --- .../tests/api/check-params/user-notifications.ts | 51 +++++++++++++++++----- 1 file changed, 41 insertions(+), 10 deletions(-) (limited to 'server/tests/api/check-params/user-notifications.ts') diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts index 635f5c9a3..714f481e9 100644 --- a/server/tests/api/check-params/user-notifications.ts +++ b/server/tests/api/check-params/user-notifications.ts @@ -96,6 +96,16 @@ describe('Test user notifications API validators', function () { statusCodeExpected: 400 }) + await makePostBodyRequest({ + url: server.url, + path, + fields: { + ids: [ ] + }, + token: server.accessToken, + statusCodeExpected: 400 + }) + await makePostBodyRequest({ url: server.url, path, @@ -131,18 +141,39 @@ describe('Test user notifications API validators', function () { }) }) + describe('When marking as read my notifications', function () { + const path = '/api/v1/users/me/notifications/read-all' + + it('Should fail with a non authenticated user', async function () { + await makePostBodyRequest({ + url: server.url, + path, + statusCodeExpected: 401 + }) + }) + + it('Should succeed with the correct parameters', async function () { + await makePostBodyRequest({ + url: server.url, + path, + token: server.accessToken, + statusCodeExpected: 204 + }) + }) + }) + describe('When updating my notification settings', function () { const path = '/api/v1/users/me/notification-settings' const correctFields: UserNotificationSetting = { - newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION, - newCommentOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION, - videoAbuseAsModerator: UserNotificationSettingValue.WEB_NOTIFICATION, - blacklistOnMyVideo: UserNotificationSettingValue.WEB_NOTIFICATION, - myVideoImportFinished: UserNotificationSettingValue.WEB_NOTIFICATION, - myVideoPublished: UserNotificationSettingValue.WEB_NOTIFICATION, - commentMention: UserNotificationSettingValue.WEB_NOTIFICATION, - newFollow: UserNotificationSettingValue.WEB_NOTIFICATION, - newUserRegistration: UserNotificationSettingValue.WEB_NOTIFICATION + newVideoFromSubscription: UserNotificationSettingValue.WEB, + newCommentOnMyVideo: UserNotificationSettingValue.WEB, + videoAbuseAsModerator: UserNotificationSettingValue.WEB, + blacklistOnMyVideo: UserNotificationSettingValue.WEB, + myVideoImportFinished: UserNotificationSettingValue.WEB, + myVideoPublished: UserNotificationSettingValue.WEB, + commentMention: UserNotificationSettingValue.WEB, + newFollow: UserNotificationSettingValue.WEB, + newUserRegistration: UserNotificationSettingValue.WEB } it('Should fail with missing fields', async function () { @@ -150,7 +181,7 @@ describe('Test user notifications API validators', function () { url: server.url, path, token: server.accessToken, - fields: { newVideoFromSubscription: UserNotificationSettingValue.WEB_NOTIFICATION }, + fields: { newVideoFromSubscription: UserNotificationSettingValue.WEB }, statusCodeExpected: 400 }) }) -- cgit v1.2.3