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

fix: unit-tests-only (just testing to enable unit tests-only action) #238

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/no-unused-vars': ['warn', { 'argsIgnorePattern': '^_', 'varsIgnorePattern': "^_" }],
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-tests-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
APP_SEGMENT_KEY: ${{ secrets.APP_SEGMENT_KEY }}
strategy:
matrix:
node-version: [16.x]
node-version: [20.x]
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand Down
102 changes: 45 additions & 57 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,49 @@
# name: run-tests
# on:
# push:
# branches:
# - 'master'
# - 'develop'
# pull_request:
# branches:
# - 'master'
# - 'develop'
# jobs:
# run-tests:
# environment: test
# runs-on: ubuntu-latest
# strategy:
# matrix:
# node-version: [16.x]
# services:
# postgres:
# image: postgres:latest
# env:
# POSTGRES_DB: xCloud_test
# POSTGRES_PASSWORD: example
# POSTGRES_USER: postgres
# ports:
# - 5432:5432
# options: >-
# --health-cmd pg_isready
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
name: Run tests
on:
push:
branches:
- 'master'
- 'develop'
pull_request:
branches:
- 'master'
- 'develop'
jobs:
run-tests:
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
environment:
name: development
strategy:
matrix:
node-version: [20.x]
steps:
- name: Checkout repo
uses: actions/checkout@v3

# steps:
# - uses: actions/checkout@v2
# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v1
# with:
# node-version: ${{ matrix.node-version }}
# registry-url: 'https://npm.pkg.github.com'
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://npm.pkg.github.com'

# - run: echo "registry=https://registry.yarnpkg.com/" > .npmrc
# - run: echo "@internxt:registry=https://npm.pkg.github.com" >> .npmrc
# # You cannot read packages from other private repos with GITHUB_TOKEN
# # You have to use a PAT instead https://github.com/actions/setup-node/issues/49
# - run: echo //npm.pkg.github.com/:_authToken=${{ secrets.PERSONAL_ACCESS_TOKEN }} >> .npmrc
# - run: echo "always-auth=true" >> .npmrc
# We should see why permissions field is not doing the job. This should be removed
- run: echo "registry=https://registry.yarnpkg.com/" > .npmrc
- run: echo "@internxt:registry=https://npm.pkg.github.com" >> .npmrc
# You cannot read packages from other private repos with GITHUB_TOKEN
# You have to use a PAT instead https://github.com/actions/setup-node/issues/49
- run: echo //npm.pkg.github.com/:_authToken=${{ secrets.PERSONAL_ACCESS_TOKEN }} >> .npmrc
- run: echo "always-auth=true" >> .npmrc

# - name: Lint & Test
# run: yarn && yarn run test
- name: Setup environment
uses: isbang/[email protected]
with:
compose-file: './infrastructure/docker-compose.yml'

# - name: Test E2E
# env:
# RDS_HOSTNAME: localhost
# RDS_DBNAME: xCloud_test
# RDS_USERNAME: postgres
# RDS_PASSWORD: example
# RDS_PORT: 5432
# SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
# SENDGRID_MODE_SANDBOX: true
# APP_SEGMENT_KEY: ${{ secrets.APP_SEGMENT_KEY }}
# run: yarn migrate:test && yarn run test:e2e
- name: Install dependencies
run: yarn

- name: Run unit tests
run: yarn test
2 changes: 1 addition & 1 deletion infrastructure/development.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16-alpine
FROM node:20.10-alpine

WORKDIR /usr/app

Expand Down
4 changes: 2 additions & 2 deletions seeders/20230308180046-test-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const referredTestUser = {
};

module.exports = {
async up(queryInterface, Sequelize) {
async up(queryInterface) {
/**
* Add seed commands here.
*
Expand All @@ -69,7 +69,7 @@ module.exports = {
}
},

async down(queryInterface, Sequelize) {
async down(queryInterface) {
/**
* Add commands to revert seed here.
*
Expand Down
129 changes: 119 additions & 10 deletions seeders/20230607000000-create-folders.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
const { v4 } = require('uuid');
const { Op, Sequelize } = require('sequelize');

let folderOneUUID, folderTwoUUID;
const foldersNames = [
'FolderOne',
'FolderTwo',
'FolderFather',
'RemovedFolder',
'DeletedFolder',
'NormalFolder',
];

module.exports = {
async up(queryInterface) {
Expand All @@ -22,14 +29,18 @@ module.exports = {
const existingFolders = await queryInterface.sequelize.query(
`SELECT * FROM folders WHERE name IN (:names)`,
{
replacements: { names: ['FolderOne', 'FolderTwo'] },
replacements: {
names: foldersNames,
},
type: Sequelize.QueryTypes.SELECT,
},
);

if (existingFolders.length > 0) {
if (existingFolders.length === foldersNames.length) {
console.log(
'Folders with the names "FolderOne" and/or "FolderTwo" already exist. Skipping creation.',
`Folders with the names ${foldersNames.join(
',',
)} already exist. Skipping creation.`,
);
return;
}
Expand All @@ -48,8 +59,6 @@ module.exports = {
updated_at: new Date(),
};

folderOneUUID = folderOne.uuid;

const folderTwo = {
parent_id: null,
name: 'FolderTwo',
Expand All @@ -64,18 +73,118 @@ module.exports = {
updated_at: new Date(),
};

folderTwoUUID = folderTwo.uuid;
const folderFather = createFolderObject(
'FolderFather',
'bucketFather',
users[0].id,
null,
);

await queryInterface.bulkInsert('folders', [folderFather]);

await queryInterface.bulkInsert('folders', [folderOne, folderTwo]);
const fatherFolderSaved = await queryInterface.sequelize.query(
`SELECT * FROM folders WHERE uuid = :uuid`,
{
replacements: { uuid: folderFather.uuid },
type: Sequelize.QueryTypes.SELECT,
},
);

const deletedFolder = createDeletedFolderObject(
'DeletedFolder',
'bucketThree',
users[0].id,
fatherFolderSaved[0].id,
fatherFolderSaved[0].uuid,
);

const removedFolder = createRemovedFolderObject(
'RemovedFolder',
'bucketFour',
users[0].id,
fatherFolderSaved[0].id,
fatherFolderSaved[0].uuid,
);

const normalFolder = createFolderObject(
'NormalFolder',
'bucketFive',
users[0].id,
fatherFolderSaved[0].id,
fatherFolderSaved[0].uuid,
);

await queryInterface.bulkInsert('folders', [
folderOne,
folderTwo,
removedFolder,
deletedFolder,
normalFolder,
]);
},

async down(queryInterface, Sequelize) {
async down(queryInterface) {
await queryInterface.bulkDelete(
'folders',
{
uuid: { [Op.in]: [folderOneUUID, folderTwoUUID] },
name: {
[Op.in]: foldersNames,
},
},
{},
);
},
};

function createFolderObject(name, bucket, userId, parentId, parentUUID) {
return {
parent_id: parentId || null,
parent_uuid: parentUUID || null,
name,
bucket,
user_id: userId,
uuid: v4(),
plain_name: name,
encrypt_version: '1.0',
deleted: false,
removed: false,
created_at: new Date(),
updated_at: new Date(),
};
}

function createDeletedFolderObject(name, bucket, userId, parentId, parentUUID) {
return {
parent_id: parentId,
parent_uuid: parentUUID,
name,
bucket,
user_id: userId,
uuid: v4(),
plain_name: name,
encrypt_version: '1.0',
deleted: true,
removed: false,
deleted_at: new Date(),
created_at: new Date(),
updated_at: new Date(),
};
}

function createRemovedFolderObject(name, bucket, userId, parentId, parentUUID) {
return {
parent_id: parentId,
parent_uuid: parentUUID,
name,
bucket,
user_id: userId,
uuid: v4(),
plain_name: name,
encrypt_version: '1.0',
deleted: false,
removed: true,
removed_at: new Date(),
created_at: new Date(),
updated_at: new Date(),
};
}
13 changes: 10 additions & 3 deletions seeders/20230614000000-create-share.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const { v4 } = require('uuid');
const { Op } = require('sequelize');

module.exports = {
async up(queryInterface, Sequelize) {
Expand All @@ -14,9 +13,17 @@ module.exports = {
},
);

const folders = await queryInterface.sequelize.query(
'SELECT * FROM folders WHERE user_id IN (:usersIds)',
{
replacements: { usersIds: [users[0].id, users[1].id] },
type: Sequelize.QueryTypes.SELECT,
},
);

const shareOne = {
id: 1,
folder_id: 1,
folder_id: folders[0].id,
user_id: users[0].id,
bucket: 'bucketOne',
file_token: v4(),
Expand All @@ -38,6 +45,6 @@ module.exports = {
},

async down(queryInterface) {
await queryInterface.bulkDelete('shares', null, {});
await queryInterface.bulkDelete('shares', { id: 1 }, {});
},
};
Loading