Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add tests + JS, add readme, rename to notifer, bump to 1.0.1
- Loading branch information
Showing
10 changed files
with
4,062 additions
and
715 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules/ | ||
lib/ | ||
src/test.ts | ||
src/playground.ts | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,20 @@ | ||
# notifer.js | ||
# notifer | ||
A simple libary to interface with an NTFY/our own notification server. | ||
|
||
# Features | ||
[x] Publish notifications | ||
[] Subcribe to a channel and listen to it's notifications | ||
|
||
# Usage | ||
Useage is really simple, just import the libary and use the publish function to send a notification to a channel. | ||
|
||
```js | ||
const { notifer } = require('@sticksdev/notifer') | ||
|
||
const client = new notifer() // A url can also be passed here, if not, it defaults to our instance (notify.hep.gg) | ||
client.REST.publishNotification('channelname', "test message", "Test Notification").then((res) => { | ||
console.log(res) // Returns an APIBaseResponse or IAPIErrorResponse | ||
}) | ||
``` | ||
|
||
All options and types are documented in the code, so you can use your IDE to get the types and option. If you have any questions/suggestions/bugs, feel free to open an issue. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { notifer } from "../src/main"; | ||
import { APIBaseResponse } from "../src/objects/APIBaseResponse"; | ||
import { IAPIErrorResponse } from "../src/objects/APIErrorResponse"; | ||
|
||
const client = new notifer() | ||
const randomChannelName = Math.random().toString(36).substring(7); | ||
|
||
describe("REST", () => { | ||
it("should return a promise on publishNotification", () => { | ||
const promise = client.REST.publishNotification(`nullchannel-${randomChannelName}`, "JEST Test", "This is a test from JEST") | ||
expect(promise).toBeInstanceOf(Promise); | ||
}); | ||
|
||
it("should return an APIBaseResponse on publishNotification success", async () => { | ||
const response = await client.REST.publishNotification(`nullchannel-${randomChannelName}`, "JEST Test", "This is a test from JEST") | ||
expect(response).toBeInstanceOf(APIBaseResponse) | ||
}); | ||
|
||
it("should return an IAPIErrorResponse on publishNotification failure", async () => { | ||
// FIXME: Ntfy.sh returns an error on the JSON post endpoint ("Unauthorized") persumably because of access control rules | ||
// But this may change in the future, so we should probably mock this | ||
const tempclient = await new notifer("https://ntfy.sh") | ||
const response = await tempclient.REST.publishNotification(`nullchannel-${randomChannelName}`, "JEST Test", "This is a test from JEST") | ||
|
||
expect(response).toHaveProperty("error") | ||
expect(response).toBeInstanceOf(IAPIErrorResponse) | ||
}); | ||
|
||
it("should be able to set auth token", () => { | ||
const tempclient = new notifer() | ||
tempclient.REST.setBasicCreditentials("test", "test") | ||
|
||
expect(tempclient.REST.basicAuthUsername).toBe("test") | ||
expect(tempclient.REST.basicAuthPassword).toBe("test") | ||
expect(tempclient.REST.useBasicAuth).toBe(true); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { RESTNotifyClient } from "../src/classes/REST"; | ||
import { notifer } from "../src/main"; | ||
|
||
const client = new notifer(); | ||
|
||
describe("Main Class", () => { | ||
it("should be able to create a new instance of the main class", () => { | ||
expect(client).toBeDefined(); | ||
}); | ||
|
||
it("should have a REST property", () => { | ||
expect(client.REST).toBeDefined(); | ||
expect(client.REST).toBeInstanceOf(RESTNotifyClient); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { Config } from "@jest/types" | ||
|
||
const config: Config.InitialOptions = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
verbose: true, | ||
collectCoverage: true, | ||
modulePathIgnorePatterns: ["<rootDir>/lib"], | ||
} | ||
|
||
export default config |
Oops, something went wrong.