assert#rejects TypeScript Examples
The following examples show how to use
assert#rejects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: change-push-token.test.ts From erouska-firebase with MIT License | 6 votes |
describe("changePushToken", () => {
it("should not accept unauthorized calls", async () => {
await rejects(async () => {
await changePushTokenMock({});
}, new functions.https.HttpsError("unauthenticated", "Chybějící autentizace"));
});
it("should not accept wrong input", async () => {
await rejects(async () => {
await changePushTokenMock({}, createAuth());
}, new functions.https.HttpsError("invalid-argument", "Wrong arguments"));
});
it("should not accept missing BUID", async () => {
await rejects(async () => {
await changePushTokenMock(makeArguments("buid1", ""), createAuth());
}, new functions.https.HttpsError("unauthenticated", "Zařízení neexistuje nebo nepatří Vašemu účtu"));
});
it("should not accept BUID not owned by the user", async () => {
const buid = await registerBuidMock(makeDeviceData(), createAuth("different-uid", "my-phone"));
await rejects(async () => {
await changePushTokenMock(makeArguments(buid.buid, ""), createAuth());
}, new functions.https.HttpsError("unauthenticated", "Zařízení neexistuje nebo nepatří Vašemu účtu"));
});
it("should change token of BUID owned by the user", async () => {
const auth = createAuth();
const buid = await registerBuidMock(makeDeviceData(), auth);
const token = "my-token";
await changePushTokenMock(makeArguments(buid.buid, token), auth);
const doc = await firestore().collection("registrations").doc(buid.buid).get();
equal(doc.get("pushRegistrationToken"), token);
});
});
Example #2
Source File: is-buid-active.test.ts From erouska-firebase with MIT License | 6 votes |
describe("isBuidActive", () => {
it("should not accept unauthorized calls", async () => {
await rejects(async () => {
await isBuidActiveMock({});
}, new functions.https.HttpsError("unauthenticated", "Chybějící autentizace"));
});
it("should not accept wrong input", async () => {
await rejects(async () => {
await isBuidActiveMock({}, createAuth());
}, new functions.https.HttpsError("invalid-argument", "Wrong arguments"));
});
it("should return false if BUID does not exist", async () => {
equal(await isBuidActiveMock(makeBuid("buid1"), createAuth()), false);
});
it("should return false if BUID is not owned by the user", async () => {
const buid = await registerBuidMock(makeDeviceData(), createAuth("different-uid", "my-phone"));
equal(await isBuidActiveMock(makeBuid(buid.buid), createAuth()), false);
});
it("should return true if BUID is owned by the user", async () => {
const auth = createAuth();
const buid = await registerBuidMock(makeDeviceData(), auth);
equal(await isBuidActiveMock(makeBuid(buid.buid), auth), true);
});
});
Example #3
Source File: register-buid.test.ts From erouska-firebase with MIT License | 4 votes |
describe("registerBuid", () => {
it("should not accept unauthorized calls", async () => {
await rejects(async () => {
await registerBuidMock({});
}, new functions.https.HttpsError("unauthenticated", "Chybějící autentizace"));
});
it("should not accept users without phone numbers", async () => {
const auth = {
auth: {
uid: "1"
}
};
await rejects(async () => {
await registerBuidMock(makeDeviceData(), auth);
}, new functions.https.HttpsError("failed-precondition", "Chybí telefonní číslo"));
await rejects(async () => {
await registerBuidMock(makeDeviceData(null), auth);
}, new functions.https.HttpsError("failed-precondition", "Chybí telefonní číslo"));
});
it("should not accept wrong input", async () => {
await rejects(async () => {
await registerBuidMock({}, createAuth());
}, new functions.https.HttpsError("invalid-argument", "Wrong arguments"));
await rejects(async () => {
await registerBuidMock({
model: "model1",
manufacturer: "model2"
}, createAuth("uid1", "123456789"));
}, new functions.https.HttpsError("invalid-argument", "Wrong arguments"));
await rejects(async () => {
await registerBuidMock(makeDeviceData("123"), createAuth("uid1", "123456789"));
}, new functions.https.HttpsError("invalid-argument", "Špatné parametry"));
});
it("should create a user with the correct phone number", async () => {
const fuid = "uid1";
const phone = "123456789";
await registerBuidMock(makeDeviceData(), createAuth(fuid, phone));
const doc = await firestore().collection("users").doc(fuid).get();
equal(doc.exists, true);
equal(doc.get("registrationCount"), 1);
equal(doc.get("unverifiedPhoneNumber"), undefined);
});
it("should create BUID", async () => {
const fuid = "uid1";
const phone = "123456789";
const data = makeDeviceData();
const response = await registerBuidMock(data, createAuth(fuid, phone));
const buid = response.buid;
const doc = await firestore().collection("registrations").doc(buid).get();
equal(doc.exists, true);
equal(doc.get("fuid"), fuid);
equal(doc.get("model"), data.model);
equal(doc.get("manufacturer"), data.manufacturer);
equal(doc.get("platform"), data.platform);
equal(doc.get("platformVersion"), data.platformVersion);
equal(doc.get("locale"), data.locale);
equal(doc.get("pushRegistrationToken"), data.pushRegistrationToken);
});
it("should create TUIDs", async () => {
const fuid = "uid1";
const phone = "123456789";
const data = makeDeviceData();
const response = await registerBuidMock(data, createAuth(fuid, phone));
const buid = response.buid;
const tuids = response.tuids;
const dbTuids = [];
for (const doc of (await firestore().collection("tuids").where("buid", "==", buid).get()).docs) {
equal(doc.get("buid"), buid);
equal(doc.get("fuid"), fuid);
dbTuids.push(doc.id);
}
expect(tuids).to.have.members(dbTuids);
});
it("should support multiple BUIDs per user", async () => {
const fuid = "uid1";
const phone = "123456789";
const data = makeDeviceData();
const buids = await Promise.all([0, 0, 0].map(() => registerBuidMock(data, createAuth(fuid, phone))));
const doc = await firestore().collection("users").doc(fuid).get();
equal(doc.get("registrationCount"), buids.length);
for (const buid of buids) {
const buidDoc = await firestore().collection("registrations").doc(buid.buid).get();
equal(buidDoc.exists, true);
}
});
it("should not allow too many BUIDs per user", async () => {
const auth = createAuth();
const data = makeDeviceData();
await Promise.all(Array.from(Array(MAX_BUIDS_PER_USER)).map(() => registerBuidMock(data, auth)));
await rejects(async () => {
await registerBuidMock(data, auth);
}, new functions.https.HttpsError("resource-exhausted", "Na Vašem účtu je již příliš mnoho registrovaných zařízení"));
});
it("should allow users with unverified phone numbers", async () => {
const uid = "uid1";
const phone = "phone1";
const auth = {
auth: {
uid,
}
};
await registerBuidMock(makeDeviceData(phone), auth);
const doc = await firestore().collection("users").doc(uid).get();
equal(doc.get("unverifiedPhoneNumber"), phone);
});
});