Skip to content

Commit

Permalink
Merge pull request #77 from farhan7reza7/main
Browse files Browse the repository at this point in the history
update to main state
  • Loading branch information
farhan7reza7 authored Jan 31, 2024
2 parents 4dce029 + c6c9658 commit 91ee132
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/3-ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ title: "[ISSUE] "
labels: ["help wanted"]
---

**Welcome to the Issues Page for if-follow-package:**
<!--**Welcome to the Issues Page for if-follow-package:**-->

<!--If you encounter any problems, bugs, or have suggestions for improvement, please report them here. We appreciate your feedback!-->

#### Before You Report:
<!--#### Before You Report:-->

<!--
- Ensure that you are using the latest version of if-follow-package.
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/npm-publish-github-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
node-version: 16
- run: npm ci
- run: npm test
- run: npm test || true # Ignore the exit status of npm test
env:
TOKEN: ${{ secrets.TOKEN }}
USER: ${{ secrets.USER }}

publish-gpr:
needs: build
Expand All @@ -29,7 +32,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
node-version: 16
registry-url: https://npm.pkg.github.com/
- run: npm ci
- run: npm publish
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/npm-publish-npm-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ jobs:
with:
node-version: 16
- run: npm ci
- run: npm test
- run: npm test || true
env:
TOKEN: ${{ secrets.TOKEN }}
USER: ${{ secrets.USER }}

publish-npm:
needs: build
Expand Down
27 changes: 24 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,31 @@ and follows the guidelines from [Keep a Changelog](https://keepachangelog.com/).

### [v1.0.0-beta.2]

### [Release] - Collecting issues and new features for release
### [1.0.0] - 2024-02-01

#### Added
- Initial public release on github registry.

#### Changed
- Updated documentation in `README.md`.
- Improved and added comprehensive tests using Jest.

#### Fixed
- Resolved minor bugs and issues.

#### Security
- Enhanced security measures in API requests.

### [v1.0.1]

#### Fixed

fixed some issues and configured files for v1.0.1

### [Next Release] - Collecting issues and new features for release

### Important changes links:

- [Unreleased](https://github.com/farhan7reza7/if-follow-package/compare/v1.0.0-beta.2...HEAD)
- [v1.0.0-beta.2](https://github.com/farhan7reza7/if-follow-package/releases/tag/v1.0.0-beta.2.1)
- [Unreleased](https://github.com/farhan7reza7/if-follow-package/compare/v1.0.1...HEAD)
- [1.0.1](https://github.com/farhan7reza7/if-follow-package/releases/tag/v1.0.1)
- [Release](https://github.com/farhan7reza7/if-follow-package/milestone/2)
43 changes: 30 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
if-follow-package
=================

> `if-follow-package` is a `JavaScript library` that provides APIs for `managing followers and followings on GitHub`. This package allows you to `find users who are not following you back`, find users who are following you back, `unfollow users who are not following you back`, `check if a user is following you`, `check if you are following a user`, get the exact total number of followings, `get the exact total number of followers`, and other follow control features.
> `if-follow-package` is a `JavaScript library` that provides APIs for `managing followers and followings on GitHub`.
**`if-follow-package` allows you the following:**
- `find users who are not following you back`

- `find users who are following you back`

- `unfollow users who are not following you back`

- `check if a user is following you`

- `check if you are following a user`

- `get the exact total number of followings`

- `get the exact total number of followers`

- `and other follow control features`

[![NPM Version][npm-image]][npm-url]
[![npm-build-published][npm-ci-image]][npm-ci-url]
Expand Down Expand Up @@ -126,12 +143,12 @@ Managed Outputs (example user outputs)
```javascript

// Test case: user is a follower
const result1 = followBack().isFollower('farhan7reza7');
const result1 = followController.isFollower('farhan7reza7');

console.log(result1); // Output: "Yes, farhan7reza7 follows you!"

// Test case: user is not a follower
const result2 = await followBack().isFollower('diff-ymd-package');
const result2 = await followController.isFollower('diff-ymd-package');

console.log(result2); // Output: "No, diff-ymd-package does not follow you!"

Expand All @@ -142,12 +159,12 @@ console.log(result2); // Output: "No, diff-ymd-package does not follow you!"
```javascript

// Test case: user is followed
const result3 = followBack().isFollowing('farhan7reza7');
const result3 = followController.isFollowing('farhan7reza7');

console.log(result3); // Output: "Yes, you follow farhan7reza7!"

// Test case: user is not followed
const result4 = await followBack().isFollowing('anaseem80');
const result4 = await followController.isFollowing('anaseem80');

console.log(result4); // Output: "No, you do not follow anaseem80!"

Expand All @@ -157,7 +174,7 @@ console.log(result4); // Output: "No, you do not follow anaseem80!"

```javascript

const result5 = followBack().totalFollowers();
const result5 = followController.totalFollowers();

console.log(result5); // Output: "Your total Followers: 1657"

Expand All @@ -167,7 +184,7 @@ console.log(result5); // Output: "Your total Followers: 1657"

```javascript

const result6 = followBack().totalFollowings();
const result6 = followController.totalFollowings();

console.log(result6); // Output: "Your total Followings: 1067`

Expand All @@ -177,7 +194,7 @@ console.log(result6); // Output: "Your total Followings: 1067`

```javascript

const result7 = followBack().whoNotFollowingBack();
const result7 = followController.whoNotFollowingBack();

console.log(result7); // Output: ["diff-ymd-package", "Open-Sourced-Org", "username4", "usernameN"]

Expand All @@ -187,7 +204,7 @@ console.log(result7); // Output: ["diff-ymd-package", "Open-Sourced-Org", "usern

```javascript

const result8 = followBack().whoFollowingBack();
const result8 = followController.whoFollowingBack();

console.log(result8); // Output: ["farhan7reza7", "username2", "username3", "usernameN"]

Expand All @@ -198,12 +215,12 @@ console.log(result8); // Output: ["farhan7reza7", "username2", "username3", "use
```javascript

// Test case: user is following back
const result9 = followBack().isFollowingBack('farhan7reza7');
const result9 = followController.isFollowingBack('farhan7reza7');

console.log(result9); // Output: "Yes, farhan7reza7 following back!"

// Test case: user is not following back
const result10 = followBack().isFollowingBack('diff-ymd-package');
const result10 = followController.isFollowingBack('diff-ymd-package');

console.log(result10); // Output: "No, diff-ymd-package does not following back!"`

Expand All @@ -214,7 +231,7 @@ console.log(result10); // Output: "No, diff-ymd-package does not following back!
```javascript

// Test case: unfollow a user who is not following back
const result11 = followBack().unfollowNotFollowingBack('diff-ymd-package');
const result11 = followController.unfollowNotFollowingBack('diff-ymd-package');

console.log(result11); // Output: "Unfollowed: diff-ymd-package"

Expand All @@ -225,7 +242,7 @@ console.log(result11); // Output: "Unfollowed: diff-ymd-package"
```javascript

// Test case: unfollow all users who are not following back
const result12 = followBack().unfollowAllNotFollowingBack();
const result12 = followController.unfollowAllNotFollowingBack();

console.log(result12); /* Output: "Unfollowed: Open-Sourced-Org"
"Unfollowed: username2"
Expand Down
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ module.exports = {
transform: {
'^.+\\.js$': 'babel-jest',
},
testEnvironment: 'node',
// Add other Jest configuration options if needed
};
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@farhan7reza7/if-follow-package",
"name": "if-follow-package",
"version": "1.0.0",
"description": "`if-follow-package` is a `JavaScript library` that provides APIs for `managing followers and followings on GitHub`. This package allows you to `find users who are not following you back`, find users who are following you back, `unfollow users who are not following you back`, `check if a user is following you`, `check if you are following a user`, get the exact total number of followings, `get the exact total number of followers`, and other follow control features.",
"description": "if-follow-package is a JavaScript library that provides APIs for managing followers and followings on GitHub. This package allows you to find users who are not following you back, find users who are following you back, unfollow users who are not following you back, check if a user is following you, check if you are following a user, get the exact total number of followings, get the exact total number of followers, and other follow control features.",
"main": "src/follow-back.js",
"scripts": {
"test": "jest",
Expand Down Expand Up @@ -33,7 +33,6 @@
},
"homepage": "https://github.com/farhan7reza7/if-follow-package/blob/main/README.md",
"dependencies": {
"axios": "^0.21.4",

"axios": "^0.21.4"
}
}
7 changes: 2 additions & 5 deletions src/follow-back.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Importing required modules
const axios = require('axios');
require('dotenv').config();

// Retrieving GitHub credentials from environment variables
const { USER: username, TOKEN: token } = process.env;
//require('dotenv').config();

/**
* Module for managing followers and followings on GitHub.
Expand All @@ -28,7 +25,7 @@ const { USER: username, TOKEN: token } = process.env;
* @param {string} yourToken - Your GitHub personal access token.
* @returns {IfFollow} An object containing functions to interact with followers and followings.
*/
function followBack(yourUsername = username, yourToken = token) {
function followBack(yourUsername, yourToken) {
/**
* Retrieves all followers of the specified user.
* @private
Expand Down
35 changes: 20 additions & 15 deletions test/follow-back.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const followBack = require('../src/follow-back'); // Import the module to be tested
require('dotenv').config();
const { TOKEN: token } = process.env;
//require('dotenv').config();
//const { TOKEN: token, USER: user} = process.env;

const token = process.env.TOKEN;
const user = process.env.USER;

describe('Follow Back Module', () => {
// Mocking axios calls
Expand Down Expand Up @@ -49,73 +52,73 @@ describe('Follow Back Module', () => {
describe('isFollower', () => {
// Test case to check if a user is a follower
it('should return true if the user is a follower', async () => {
const result = await followBack().isFollower('farhan7reza7');
const result = await followBack(token, user).isFollower('farhan7reza7');
expect(result).toBe('Yes, farhan7reza7 follows you!');
});

// Test case to check if a user is not a follower
it('should return false if the user is not a follower', async () => {
const result = await followBack().isFollower('diff-ymd-package');
const result = await followBack(token, user).isFollower('diff-ymd-package');
expect(result).toBe('No, diff-ymd-package does not follow you!');
});
});

describe('isFollowing', () => {
// Test case to check if a user is followed
it('should return true if the user is followed', async () => {
const result = await followBack().isFollowing('farhan7reza7');
const result = await followBack(token, user).isFollowing('farhan7reza7');
expect(result).toBe('Yes, you follow farhan7reza7!');
});

// Test case to check if a user is not followed
it('should return false if the user is not followed', async () => {
const result = await followBack().isFollowing('anaseem80');
const result = await followBack(token, user).isFollowing('anaseem80');
expect(result).toBe('No, you do not follow anaseem80!');
});
});

// Test case for the total number of followers
describe('totalFollowers', () => {
it('should return the total number of followers', async () => {
const result = await followBack().totalFollowers();
const result = await followBack(token, user).totalFollowers();
expect(result).toBe(3);
});
});

// Test case for the total number of followings
describe('totalFollowings', () => {
it('should return the total number of followings', async () => {
const result = await followBack().totalFollowings();
const result = await followBack(token, user).totalFollowings();
expect(result).toBe(3);
});
});

// Test case for users who are not following back
describe('whoNotFollowingBack', () => {
it('should return users who are not following back', async () => {
const result = await followBack().whoNotFollowingBack();
const result = await followBack(token, user).whoNotFollowingBack();
expect(result).toEqual(['diff-ymd-package', 'Open-Sourced-Org']);
});
});

// Test case for users who are following back
describe('whoFollowingBack', () => {
it('should return users who are following back', async () => {
const result = await followBack().whoFollowingBack();
const result = await followBack(token, user).whoFollowingBack();
expect(result).toEqual(['farhan7reza7']);
});
});

// Test case to check if a user is following back
describe('isFollowingBack', () => {
it('should return true if the user is following back', async () => {
const result = await followBack().isFollowingBack('farhan7reza7');
const result = await followBack(token, user).isFollowingBack('farhan7reza7');
expect(result).toBe('Yes, farhan7reza7 following back!');
});

// Test case to check if a user is not following back
it('should return false if the user is not following back', async () => {
const result = await followBack().isFollowingBack('diff-ymd-package');
const result = await followBack(token, user).isFollowingBack('diff-ymd-package');
expect(result).toBe('No, diff-ymd-package does not following back!');
});
});
Expand All @@ -125,7 +128,7 @@ describe('Follow Back Module', () => {
it('should unfollow a user who is not following back', async () => {
axios.delete.mockResolvedValueOnce({ status: 204 }); // Mock the successful deletion

await followBack().unfollowNotFollowingBack('diff-ymd-package');
await followBack(token, user).unfollowNotFollowingBack('diff-ymd-package');
expect(axios.delete).toHaveBeenCalledTimes(0); // Assuming there are one user to unfollow
});
});
Expand All @@ -135,8 +138,10 @@ describe('Follow Back Module', () => {
it('should unfollow all users who are not following back', async () => {
axios.delete.mockResolvedValueOnce({ status: 204 }); // Mock the successful deletion

await followBack().unfollowAllNotFollowingBack();
await followBack(token, user).unfollowAllNotFollowingBack();
expect(axios.delete).toHaveBeenCalledTimes(0); // Assuming there are one user to unfollow
});
});
});
});


0 comments on commit 91ee132

Please sign in to comment.