Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAMA-46 correcting the names of the message_status & file collections #75

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion app/models/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class File extends BaseModel {
}

static get collection() {
return "file";
return "files";
}

static get visibleFields() {
Expand Down
2 changes: 1 addition & 1 deletion app/models/message_status.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class MessageStatus extends BaseModel {
}

static get collection() {
return "message_status";
return "message_statuses";
}

static get visibleFields() {
Expand Down
2 changes: 1 addition & 1 deletion app/models/push_event.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BaseModel from "./base/base.js";

export default class PushEvents extends BaseModel {
export default class PushEvent extends BaseModel {
constructor(params) {
super(params);
}
Expand Down
4 changes: 2 additions & 2 deletions app/repositories/push_notifications_repository.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BaseRepository from "./base.js";
import PushEvents from "../models/push_event.js";
import PushEvent from "../models/push_event.js";
import PushSubscription from "../models/push_subscription.js";
import SessionRepository from "./session_repository.js";
import { ACTIVE } from "../store/session.js";
Expand Down Expand Up @@ -37,7 +37,7 @@ export default class PushNotificationsRepository extends BaseRepository {
message: JSON.stringify(pushMessage),
};

const pushEvent = new PushEvents(pushEventParams);
const pushEvent = new PushEvent(pushEventParams);
await pushEvent.save();

await this.sendPushNotification(recipients_ids, pushMessage);
Expand Down
39 changes: 39 additions & 0 deletions migrations/20231019132828-rename-file-message-status-collection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export const up = async (db, client) => {
// vv CREATE MESSAGE STATUSES vv //
let indexes = await db.collection("message_status").indexes();
indexes = indexes.filter(({ name }) => name !== "_id_");

indexes = indexes.map((index) => {
const { v, key, ...options } = index;
return { key, options };
});

const newCollection = await db.createCollection("message_statuses");
for (const { key, options } of indexes) {
await newCollection.createIndex(key, options);
}

// vv COPY MESSAGE STATUSES vv //
await db
.collection("message_status")
.aggregate([{ $out: "message_statuses" }])
.toArray();

// vv DROP MESSAGE STATUSES vv //
await db.collection("message_status").drop();

// vv FILES vv //
await db.createCollection("files");
await db
.collection("file")
.aggregate([{ $out: "files" }])
.toArray();
await db.collection("file").drop();
};

export const down = async (db, client) => {
await db
.collection("message_statuses")
.rename("message_status", { dropTarget: true });
await db.collection("files").rename("file", { dropTarget: true });
};
17 changes: 9 additions & 8 deletions test/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,21 +608,21 @@ describe("Contacts functions", async () => {
first_name: "Name11_6",
last_name: "Surname11_6",
company: "UserCompany",
email: [{ type: "work", value: "test_matched_6_email" }],
email: [{ type: "work", value: "[email protected]" }],
phone: [{ type: "home", value: "test_6_phone" }],
},
{
first_name: "Name22_6",
last_name: "Surname22_6",
company: "UserCompany",
email: [{ type: "work", value: "test_matched_6_email" }],
email: [{ type: "work", value: "[email protected]" }],
phone: [{ type: "home", value: "test_6_phone" }],
},
{
first_name: "Name33_6",
last_name: "Surname33_6",
company: "UserCompany",
email: [{ type: "work", value: "test_matched_6_email" }],
email: [{ type: "work", value: "[email protected]" }],
phone: [{ type: "home", value: "test_6_phone" }],
},
],
Expand All @@ -641,7 +641,7 @@ describe("Contacts functions", async () => {
requestData = {
request: {
user_edit: {
email: "test_matched_6_email",
email: "[email protected]",
phone: "test_6_phone",
},
id: "1",
Expand All @@ -666,6 +666,7 @@ describe("Contacts functions", async () => {
mockedWS,
requestData
);
console.log(responseData.response.contacts[0]);

assert.strictEqual(requestData.request.id, responseData.response.id);
assert.strictEqual(
Expand Down Expand Up @@ -702,7 +703,7 @@ describe("Contacts functions", async () => {
let requestData = {
request: {
user_edit: {
email: "test_matched_7_email",
email: "[email protected]",
},
id: "1",
},
Expand Down Expand Up @@ -730,15 +731,15 @@ describe("Contacts functions", async () => {
assert.strictEqual(requestData.request.id, responseData.response.id);
assert.strictEqual(
responseData.response.contacts[0].email[0].value,
"test_matched_7_email"
"[email protected]"
);
assert.strictEqual(
responseData.response.contacts[1].email[0].value,
"test_matched_7_email"
"[email protected]"
);
assert.strictEqual(
responseData.response.contacts[2].email[0].value,
"test_matched_7_email"
"[email protected]"
);
assert.strictEqual(
responseData.response.contacts[0].email[0].matched_user_id,
Expand Down
4 changes: 2 additions & 2 deletions test/push_notifications.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PushEvents from "../app/models/push_event.js";
import PushEvent from "../app/models/push_event.js";
import PushSubscription from "../app/models/push_subscription.js";
import User from "./../app/models/user.js";
import assert from "assert";
Expand Down Expand Up @@ -574,7 +574,7 @@ describe("PushNotification functions", async () => {
after(async () => {
await User.clearCollection();
await PushSubscription.clearCollection();
await PushEvents.clearCollection();
await PushEvent.clearCollection();
usersIds = [];
});
});
4 changes: 2 additions & 2 deletions test/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ describe("User cycle", async () => {
user_create: {
login: "login_12345",
password: "new_pasw31",
email: "copy_email",
email: "[email protected]",
phone: "copy_phone",
deviceId: "pc",
},
Expand Down Expand Up @@ -449,7 +449,7 @@ describe("User cycle", async () => {
const requestData = {
request: {
user_edit: {
email: "copy_email",
email: "[email protected]",
},
id: "5_1",
},
Expand Down