Skip to content

Commit

Permalink
Update to node v20 with few code changes due to npm package upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank1211 committed Feb 20, 2024
1 parent a280627 commit f82169b
Show file tree
Hide file tree
Showing 8 changed files with 7,119 additions and 4,814 deletions.
2 changes: 1 addition & 1 deletion host.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
"version": "[1.*, 3.0.0)"
},
"extensions": {
"http": {
Expand Down
13 changes: 6 additions & 7 deletions lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
@module lib/database
*/

const { MongoClient, ObjectID } = require('mongodb');
const { uuid } = require('uuidv4');
const { MongoClient, ObjectId } = require('mongodb');
const { v4: uuid } = require('uuid');

const DB_NAME = 'userfeedback';
const COLLECTION_NAME = 'feedback';
Expand All @@ -18,9 +18,7 @@ let dbClient;
const getDb = async () => {
const CONNECTION_STRING = process.env.MONGO_CONNECTION_STRING;
if (!dbClient) {
dbClient = await MongoClient.connect(CONNECTION_STRING, {
useUnifiedTopology: true,
});
dbClient = await MongoClient.connect(CONNECTION_STRING);
}
return dbClient.db(DB_NAME);
};
Expand Down Expand Up @@ -98,7 +96,8 @@ const update = async (data) => {
};

const getSinceDateQuery = (sinceDate) => {
const minObjectId = ObjectID.createFromTime(sinceDate.getTime() / 1000);

const minObjectId = ObjectId.createFromTime(sinceDate.getTime() / 1000);
return {
_id: {
$gt: minObjectId,
Expand All @@ -121,7 +120,7 @@ const getAllData = async (sinceDate = null, extraQuery = {}) => {
const data = await collection.find(query).project(fields).toArray();
return data.map((row) => ({
...row,
timestamp: ObjectID(row._id).getTimestamp(), // eslint-disable-line no-underscore-dangle
timestamp: new ObjectId(row._id).getTimestamp(), // eslint-disable-line no-underscore-dangle
}));
};

Expand Down
12 changes: 4 additions & 8 deletions lib/database.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ let connection;
let db;

beforeAll(async () => {
connection = await MongoClient.connect(
global.__MONGO_URI__, // eslint-disable-line no-underscore-dangle
{
useNewUrlParser: true,
}
connection = await MongoClient.connect(global.__MONGO_URI__, // eslint-disable-line no-underscore-dangle
);
db = connection.db('userfeedback');
});
Expand Down Expand Up @@ -86,7 +82,7 @@ describe('database select', () => {
// record the time of DB insert for use in tests. This time is only approximate
insertTime = new Date();

await db.collection('feedback').insert([{
await db.collection('feedback').insertMany([{
comments: 'This is comment 1',
isSatisfied: true,
url: 'https://example.com/1',
Expand Down Expand Up @@ -161,7 +157,7 @@ describe('database select', () => {
describe('getSatisfactionPerURL', () => {
beforeAll(async () => {
await db.collection('feedback').deleteMany({});
await db.collection('feedback').insert([{
await db.collection('feedback').insertMany([{
isSatisfied: true,
url: 'https://example.com/1?query=a',
}, {
Expand Down Expand Up @@ -214,7 +210,7 @@ describe('database select', () => {

it('URLs are lower-cased', async () => {
await db.collection('feedback').deleteMany({});
await db.collection('feedback').insert([{
await db.collection('feedback').insertMany([{
isSatisfied: true,
url: 'https://EXAMPLE.COM/',
}, {
Expand Down
Loading

0 comments on commit f82169b

Please sign in to comment.