sql
sql
* @jest-environment ./src/environments/test.environment.ts
*/
jest.setTimeout(20000);
// beforeEach(async () => {
// moduleFixture = await Test.createTestingModule({
// imports: [AppModule],
// })
// .overrideProvider(FirebaseAdminService)
// .useValue({
// uploadFile: jest.fn(() => {
// return Promise.resolve(['https://subdomain.domain.com/name']);
// }),
// getFirebaseApp: jest.fn(() => {
// return {};
// }),
// })
// .compile();
// app = moduleFixture.createNestApplication({
// cors: true,
// bodyParser: false,
// logger: ['error'],
// });
// await app.init();
// communityService = await app.resolve<CommunityService>(CommunityService);
// afterEach(async () => {
// await tournamentModel.deleteMany({});
// await activityModel.deleteMany({});
// await app.close();
// });
// const webPortalServiceMock =
// moduleFixture.get<WebportalService>(WebportalService);
// when(jest.spyOn(webPortalServiceMock, 'getClubAllActivities'))
// .calledWith(groupId)
// .mockResolvedValue(true);
// it('should return feed when activity and tournament exist', async () => {
// const groupId = 'test id';
// const filter = 'completed';
// const webPortalServiceMock =
// moduleFixture.get<WebportalService>(WebportalService);
// when(jest.spyOn(webPortalServiceMock, 'getClubAllActivities'))
// .calledWith(groupId)
// .mockResolvedValue(null);
// await tournamentModel.create(getTournamentMock(groupId));
// await activityModel.create(getActivityModelMock(groupId));
// expect(Array.isArray(resp)).toBeTruthy();
// expect((resp as any[]).length).toEqual(2);
// expect((resp as any[]).map((el) => el.groupId)).toEqual([
// groupId,
// groupId,
// ]);
// expect(
// (resp as any[]).some((el) => el.email === '[email protected]'),
// ).toBeTruthy();
// expect(
// (resp as any[]).some((el) => el.email === '[email protected]'),
// ).toBeTruthy();
// });
// it('should return feed when only activity exist', async () => {
// const groupId = 'test id';
// const filter = 'completed';
// const webPortalServiceMock =
// moduleFixture.get<WebportalService>(WebportalService);
// when(jest.spyOn(webPortalServiceMock, 'getClubAllActivities'))
// .calledWith(groupId)
// .mockResolvedValue(null);
// await activityModel.create(getActivityModelMock(groupId));
// expect(Array.isArray(resp)).toBeTruthy();
// expect((resp as any[]).length).toEqual(1);
// expect((resp as any[]).map((el) => el.groupId)).toEqual([groupId]);
// expect(
// (resp as any[]).some((el) => el.email === '[email protected]'),
// ).toBeTruthy();
// expect(
// (resp as any[]).some((el) => el.email === '[email protected]'),
// ).toBeFalsy();
// });
// it('should return error when data exist but not match in date filter', async
() => {
// const groupId = 'test 123123';
// const filter = 'upcoming';
// const webPortalServiceMock =
// moduleFixture.get<WebportalService>(WebportalService);
// when(jest.spyOn(webPortalServiceMock, 'getClubAllActivities'))
// .calledWith(groupId)
// .mockResolvedValue(null);
// await tournamentModel.create(getTournamentMock(groupId));
// await activityModel.create(getActivityModelMock(groupId));
// expect(resp).toStrictEqual({
// error: 'Activity not found for this group',
// });
// });
// });
// describe('getPostGroupById', () => {
// let app: INestApplication,
// communityService: CommunityService,
// moduleFixture: TestingModule,
// communityModel: Model<CommunityDocument>;
// beforeEach(async () => {
// moduleFixture = await Test.createTestingModule({
// imports: [AppModule],
// })
// .overrideProvider(FirebaseAdminService)
// .useValue({
// uploadFile: jest.fn(() => {
// return Promise.resolve(['https://subdomain.domain.com/name']);
// }),
// getFirebaseApp: jest.fn(() => {
// return {};
// }),
// })
// .compile();
// app = moduleFixture.createNestApplication({
// cors: true,
// bodyParser: false,
// logger: ['error'],
// });
// await app.init();
// communityService = await app.resolve<CommunityService>(CommunityService);
// afterEach(async () => {
// await communityModel.deleteMany({});
// await app.close();
// });
// when(jest.spyOn(communityModel, 'findById'))
// .calledWith(groupId)
// .mockResolvedValue(null);
// //find group
// when(jest.spyOn(communityModel, 'findById'))
// .calledWith(groupId)
// .mockResolvedValue(getCommunityModelMock(communityId));
beforeEach(async () => {
moduleFixture = await Test.createTestingModule({
imports: [AppModule],
})
.overrideProvider(FirebaseAdminService)
.useValue({
uploadFile: jest.fn(() => {
return Promise.resolve(['https://subdomain.domain.com/name']);
}),
getFirebaseApp: jest.fn(() => {
return {};
}),
})
.compile();
app = moduleFixture.createNestApplication({
cors: true,
bodyParser: false,
logger: ['error'],
});
await app.init();
communityService = await app.resolve<CommunityService>(CommunityService);
afterEach(async () => {
await communityModel.deleteMany({});
await app.close();
});
it('should return error when user is not the member of group', async () => {
const groupId = 'groupId';
const postId = 'postId';
const communityId = 'communityId';
const email = 'email';
const group = {
id: communityId,
members: [],
};
when(jest.spyOn(communityModel, 'findById'))
.calledWith(groupId)
.mockResolvedValue(group);
when(jest.spyOn(communityModel, 'updateOne'))
.calledWith({ _id: groupId }, { $pull: { posts: { _id: postId } } })
.mockResolvedValue(null);
when(jest.spyOn(communityModel, 'findById'))
.calledWith(groupId)
.mockResolvedValue(group);
when(jest.spyOn(communityModel, 'updateOne'))
.calledWith({ _id: groupId }, { $pull: { posts: { _id: postId } } })
.mockResolvedValue(groupAfterDeletePost);
'diiPvGNb40UIrJKMbgkWyS:APA91bGsxhwG9jdh8LeasfmHDpk1s3l6lR4FzdshMrOvchNoXQVFptIBjzs
gCOXuRkB6AZfuuVESXwrFTQ5JhiHkULVMsW-9XwizZWadVfEQYe6rkxn1ZcwUoKt_f0piN8JEgV885_Tw',
profilePic: '',
level: [
{ name: 'name3', img: 116, im: 3, des: 'des3' },
{ name: 'name4', img: 117, im: 4, des: 'des4' },
{ name: 'name5', img: 118, im: 5, des: 'des5' },
],
gameType: 'padel',
time: '17:4',
title: 'Testinb',
timeEnd: '17:4',
currency: 'SEK',
timeEndReal: '17:4',
playoff: false,
dateStamp: 1688022000000,
selectedTimeEndStamp: 1687694643376,
selectedTimeStamp: 1687694643376,
locations: 'US Padel ',
public: false,
courtArr: [{ title: '' }],
comments: '',
isSingle: false,
selectedpayment: 'payment',
amount: '',
numberOfPlayers: 4,
number: '',
bookedUser: 4,
playerSelf: false,
numberOfPoint: 32,
timeStampReal: 1688040240000,
gameCode: null,
lang: 'en',
bookedEmail: [],
levelRange: [
{ name: 'name3', img: 116, im: 3, des: 'des3' },
{ name: 'name4', img: 117, im: 4, des: 'des4' },
{ name: 'name5', img: 118, im: 5, des: 'des5' },
],
type: 'tournament',
matchType: 'americano',
numberOfRound: 8,
cancelDate: 48,
isCoach: 'false',
clubInfo: { clubId: '64982d6e4759fdbbc0499c6b', clubName: 'US Padel ' },
enableTeam: false,
swished: [],
players: [
{
name: 'joseftest',
email: '[email protected]',
profilePic: null,
lang: 'en',
fcmToken:
'c1UPe1HIIUGsmRSjB1lwpI:APA91bHo-8KSFJPPrtdJj-
emX5Fr1VaZ6pajZPuovmiueb4km0i7t_Ll8sz1VnpNwH_iHv_iVaZF48xVDr1mPNTJwdGUK_2aIyLQ8Xpl9
LwcvXZZZc4IsG6e84ClSNfcSOhsal_OU2QV',
isCoach: false,
level: { name: 'name7', im: 7, des: 'des7' },
pro: false,
userId: '64982d534759fdbbc0499bf3',
},
{
name: 'Superman',
email: '[email protected]',
profilePic: '',
punctuality: 0,
lang: 'en',
fcmToken:
'diiPvGNb40UIrJKMbgkWyS:APA91bGsxhwG9jdh8LeasfmHDpk1s3l6lR4FzdshMrOvchNoXQVFptIBjzs
gCOXuRkB6AZfuuVESXwrFTQ5JhiHkULVMsW-9XwizZWadVfEQYe6rkxn1ZcwUoKt_f0piN8JEgV885_Tw',
isCoach: false,
level: { name: 'name1.5', im: 1.5, des: 'des1.5' },
pro: false,
userId: '64982d534759fdbbc0499bf3',
},
{
name: 'Daniel Dawood',
email: '[email protected]',
profilePic:
'https://uploads.padelmates.co/images/rn_image_picker_lib_temp_da8ca376-d632-4d48-
9946-43eb37b036a2.jpg?alt=media&token=838c1b11-9895-4376-84e7-e9d55832b144',
punctuality: 0,
lang: 'sw',
fcmToken:
'dpQiS7m6SiuvMO2kQXn2j8:APA91bGAo45S00k8DRumcSMHy6WXHiIQvXBzqMMyrrTRkbguckbI4Fya369
YP6WesUcrpA65CXWdwO0PHCAjFBl5tyQpkAcpWxdT7KjAMI_lf-WBBLewJoZlZ3xMV5eSbEBIDsEgA5_H',
isCoach: false,
level: { name: 'name6.5', im: 6.5, des: 'des6.5' },
userId: '64982d534759fdbbc0499bf3',
pro: true,
},
],
chatId: '64982db14759fdbbc0499e19',
createdAt: '2023-06-25T12:06:09.937Z',
updatedAt: '2023-06-27T08:41:51.620Z',
__v: 0,
requestPlayers: [],
invitedList: [
{
name: 'Ashhad Khan',
email: '[email protected]',
fcmToken:
'cLfDsGVkf0V-
pizT1RSq2E:APA91bF2aNQcAxH_t_gvnP64QDUGdbn65z6KJ1MUej72FrsjnjZKKNMopY-
YgVm968OHL54cai3QzH56W5kR7c6T-UWDojFwdALdhAHiLWw8MIf0-k2nBMLEPPW39vNRbLoT7rJ-T6rY',
profilePic:
'https://platform-lookaside.fbsbx.com/platform/profilepic/?
asid=2074073742744741&height=100&width=100&ext=1625251989&hash=AeSq3smRm-2NmI-
Yp5I',
level: { name: 'name5', im: 5, des: 'des5' },
pro: false,
lang: 'en',
isCoach: false,
userId: '60b7d3980a15620004c07586',
},
{
name: 'Josef Badro',
email: '[email protected]',
profilePic:
'https://uploads.padelmates.co/images/F8B760ED-9AA8-4EA6-9E54-
E285BB00F9D2.jpg?alt=media&token=e8111809-4bcb-4257-ad8d-d3473d04f6df',
isCoach: false,
pro: true,
lang: 'sw',
fcmToken:
'eTLqW9OHkkdIu_WP0MTGG5:APA91bHjtTkhIcm0dSzLouG-
WH8iWXds47B_pLmlbKS5O7V_1At9mbMbFCg82zbIjUqJATMZzD3eJlUyo5dxabezNjrQvUb-PaC-
qzb76_7i8b7plAoqA-JV8B4tJ6W44R3En2XXMHn-',
punctuality: 5.6,
userId: '5f88ca16579d530004a4a1ab',
},
],
};
}
function getGroupPostMock() {
return {
name: 'name1',
email: '[email protected]',
profilePic: '',
userId: '64982b0e4759fdbbc04997e6',
type: 'POST',
subtype: 'TEXT',
data: {
message: 'Hey ',
postSubtitle: 'Askes a question in this group',
initialComments: [],
isCommented: false,
isLike: false,
totalComments: 0,
totalLikes: 0,
timeStamp: 1689013607488,
postImage: '',
postVideo: '',
},
timeStamp: '2023-07-10T18:26:48.428Z',
_id: 'id',
};
}
});