Skip to content

Commit

Permalink
Merge pull request #69 from SLIIT-Y3S2/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Sandaru-IT21001352 committed Oct 29, 2023
2 parents 9acb8b2 + 0f30720 commit dc83416
Show file tree
Hide file tree
Showing 58 changed files with 1,322 additions and 1,122 deletions.
22 changes: 22 additions & 0 deletions backend/src/__tests__/item.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const userPayload = {
contactNumber: "0712345678",
};


/**
* Main test suite
*/
describe("site", () => {
beforeAll(async () => {
const mongoServer = await MongoMemoryServer.create();
Expand All @@ -37,15 +41,21 @@ describe("site", () => {
await mongoose.disconnect();
await mongoose.connection.close();
});

/**
* Sub test suite 1 - POST operation
*/
describe("create item route", () => {
describe("given the user is not logged in", () => {
/* failure scenario */
it("should return a 403", async () => {
const { statusCode } = await supertest(app).post("/api/items");

expect(statusCode).toBe(403);
});
});
describe("given the user is logged in", () => {
/* success scenario */
it("should return a 200 and create the item", async () => {
const jwt = signJwt(userPayload);

Expand All @@ -60,14 +70,20 @@ describe("site", () => {
});
});
});

/**
* Sub test suite 2 - GET operation (all)
*/
describe("get item list route", () => {
describe("given the user is not logged in", () => {
/* failure scenario */
it("should return a 403", async () => {
const { statusCode } = await supertest(app).get("/api/items");
expect(statusCode).toBe(403);
});
});
describe("given the user is logged in", () => {
/* success scenario */
it("should return a 200 and get the item list", async () => {
const jwt = signJwt(userPayload);

Expand All @@ -81,8 +97,13 @@ describe("site", () => {
});
});
});

/**
* Sub test suite 3 - update site
*/
describe("update item route", () => {
describe("given the user is not logged in", () => {
/* failure scenario */
it("should return a 403", async () => {
const oldItem = await createItem(itemPayload);
const { statusCode } = await supertest(app).put(
Expand All @@ -93,6 +114,7 @@ describe("site", () => {
});
});
describe("given the user is logged in", () => {
/* success scenario */
it("should return a 200 and update the item", async () => {
const jwt = signJwt(userPayload);

Expand Down
26 changes: 26 additions & 0 deletions backend/src/__tests__/site.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const userPayload = {
contactNumber: "0712345678",
};


/**
* Main test suite
*/
describe("site", () => {
beforeAll(async () => {
const mongoServer = await MongoMemoryServer.create();
Expand All @@ -37,8 +41,14 @@ describe("site", () => {
await mongoose.disconnect();
await mongoose.connection.close();
});


/**
* Sub test suite 1 - POST operation
*/
describe("create site route", () => {
describe("given the user is not logged in", () => {
/* failure scenario */
it("should return a 403", async () => {
const { statusCode } = await supertest(app).post("/api/sites");

Expand All @@ -47,6 +57,7 @@ describe("site", () => {
});

describe("given the user is logged in", () => {
/* success scenario */
it("should return a 200 and create the site", async () => {
const jwt = signJwt(userPayload);

Expand All @@ -62,8 +73,12 @@ describe("site", () => {
});
});

/**
* Sub test suite 2 - GET operation (all)
*/
describe("get sites list route", () => {
describe("given the user is not logged in", () => {
/* failure scenario */
it("should return a 403", async () => {
const { statusCode } = await supertest(app).get("/api/sites");

Expand All @@ -72,6 +87,7 @@ describe("site", () => {
});

describe("given the user is logged in", () => {
/* success scenario */
it("should return a 200 and the sites", async () => {
const jwt = signJwt(userPayload);

Expand All @@ -92,8 +108,12 @@ describe("site", () => {
});
});

/**
* Sub test suite 3 - GET operation (particular site)
*/
describe("get site by id route", () => {
describe("given the site does not exist", () => {
/* failure scenario */
it("should return a 404", async () => {
const siteId = "site-123";
const jwt = signJwt(userPayload);
Expand All @@ -106,6 +126,7 @@ describe("site", () => {
});

describe("given the site does exist", () => {
/* success scenario */
it("should return a 200 status and the site", async () => {
const site = await createSite(sitePayload);
const jwt = signJwt(userPayload);
Expand All @@ -121,8 +142,12 @@ describe("site", () => {
});
});

/**
* Sub test suite 4 - update site
*/
describe("update site route", () => {
describe("given the user is not logged in", () => {
/* failure scenario */
it("should return a 403", async () => {
const site = await createSite(sitePayload);
const { statusCode } = await supertest(app).put(
Expand All @@ -133,6 +158,7 @@ describe("site", () => {
});

describe("given the user is logged in", () => {
/* success scenario */
it("should return a 200 and update the site", async () => {
const site = await createSite(sitePayload);
const jwt = signJwt(userPayload);
Expand Down
18 changes: 18 additions & 0 deletions backend/src/__tests__/user-management.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const userInput: CreateUserInput["body"] = {
contactNumber: "0712345678",
};

/**
* Main test suite
*/
describe("user-management", () => {
beforeAll(async () => {
const mongoServer = await MongoMemoryServer.create();
Expand All @@ -38,8 +41,12 @@ describe("user-management", () => {
await mongoose.connection.close();
});

/**
* Sub test suite 1 - POST operation
*/
describe("create user route", () => {
describe("given the user is not logged in", () => {
/* failure scenario */
it("should return a 403", async () => {
const { statusCode } = await supertest(app).post(
"/api/user-management"
Expand All @@ -50,6 +57,7 @@ describe("user-management", () => {
});

describe("given the user is logged in", () => {
/* success scenario */
it("should return a 201 and create the user", async () => {
const jwt = signJwt(userPayload);

Expand All @@ -65,8 +73,12 @@ describe("user-management", () => {
});
});

/**
* Sub test suite 2 - GET operation (all)
*/
describe("get user list route", () => {
describe("given the user is not logged in", () => {
/* failure scenario */
it("should return a 403", async () => {
const { statusCode } = await supertest(app).get("/api/user-management");

Expand All @@ -75,6 +87,7 @@ describe("user-management", () => {
});

describe("given the user is logged in", () => {
/* success scenario */
it("should return a 200 and the users", async () => {
const jwt = signJwt(userPayload);

Expand All @@ -89,8 +102,12 @@ describe("user-management", () => {
});
});

/**
* Sub test suite 4 - update user
*/
describe("update user route", () => {
describe("given the user is not logged in", () => {
/* failure scenario */
it("should return a 403", async () => {
const { statusCode } = await supertest(app).put(
`/api/user-management/${userPayload.userId}`
Expand All @@ -101,6 +118,7 @@ describe("user-management", () => {
});

describe("given the user is logged in", () => {
/* success scenario */
it("should return a 200 and update the user", async () => {
const jwt = signJwt(userPayload);

Expand Down
1 change: 1 addition & 0 deletions backend/src/service/deliver.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export async function getDeliveryList(
.populate("order")
.populate("supplier")
.populate("site")
.sort({ createdAt: -1 })
.exec();
}

Expand Down
2 changes: 1 addition & 1 deletion flutter_client/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="flutter_client"
android:label="ProcureSync"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 13 additions & 3 deletions flutter_client/lib/blocs/auth/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@ part 'auth_state.dart';

class AuthBloc extends Bloc<AuthEvent, AuthState> {
AuthBloc() : super(AuthInitial()) {
on<GetSiteManagerName>(_getSiteManagerNameEventHandeler);
on<LoginEvent>(_loginEventHandeler);
on<SignOut>(_logoutEventHandeler);
}
}

void _loginEventHandeler(LoginEvent event, Emitter<AuthState> emit) async {
void _getSiteManagerNameEventHandeler(
GetSiteManagerName event, Emitter<AuthState> emit) async {
emit(SigningIn());
AuthRepository authRepository = AuthRepository();
emit(SiteManagerNameLoading());
await authRepository.siteManagerName.then((siteManagerName) {
emit(SiteManagerName(siteManagerName));
}).catchError((onError) {
emit(SiteManagerNameLoadFailed());
});
}

print("wwwwwwwwwwwwwwwwwwwwwwwwwwwwewewewewewewewe");
void _loginEventHandeler(LoginEvent event, Emitter<AuthState> emit) async {
emit(SigningIn());
AuthRepository authRepository = AuthRepository();

Expand All @@ -34,7 +45,6 @@ void _logoutEventHandeler(SignOut event, Emitter<AuthState> emit) async {
AuthRepository authRepository = AuthRepository();
final isLoggedOut = await authRepository.logout();
if (isLoggedOut) {
// authRepository.isTokenAvailable();
emit(SignedOut());
emit(AuthInitial());
} else {
Expand Down
4 changes: 4 additions & 0 deletions flutter_client/lib/blocs/auth/auth_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ abstract class AuthEvent {
const AuthEvent();
}

class GetSiteManagerName extends AuthEvent {
const GetSiteManagerName();
}

class LoginEvent extends AuthEvent {
final String username;
final String password;
Expand Down
10 changes: 10 additions & 0 deletions flutter_client/lib/blocs/auth/auth_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ final class SigningOut extends AuthState {}
final class SignedOut extends AuthState {}

final class SignOutFailed extends AuthState {}

final class SiteManagerName extends AuthState {
final String siteManagerName;

SiteManagerName(this.siteManagerName);
}

final class SiteManagerNameLoading extends AuthState {}

final class SiteManagerNameLoadFailed extends AuthState {}
1 change: 1 addition & 0 deletions flutter_client/lib/blocs/cart/cart_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class CartBloc extends Bloc<CartEvent, CartState> {

void _clearCartHandler(ClearCartEvent event, Emitter<CartState> emit) {
cart.clear();
_temporaryProducts.clear();

emit(ProductCartUpdated(orderProducts: cart, cartTotal: 0));
}
Expand Down
27 changes: 27 additions & 0 deletions flutter_client/lib/blocs/goodReceipts/goods_receipt_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class GoodsReceiptBloc extends Bloc<GoodsReceiptEvent, GoodsReceiptState> {

GoodsReceiptBloc() : super(GoodsReceiptInitial()) {
on<GetGoodsReceiptsEvent>(_getGoodsReceiptsHandler);
on<MarkAsReceivedEvent>(_markAsReceivedHandler);
}

// Load products
Expand All @@ -34,4 +35,30 @@ class GoodsReceiptBloc extends Bloc<GoodsReceiptEvent, GoodsReceiptState> {
},
);
}

// Mark as received
void _markAsReceivedHandler(
MarkAsReceivedEvent event, Emitter<GoodsReceiptState> emit) async {
emit(
GoodsReceiptMarkingAsReceived(
goodsReceiptNumber: event.goodsReceiptNumber,
),
);

await _goodsReceiptRepository
.markedAsReceived(event.goodsReceiptNumber)
.then(
(goodsReceipt) {
emit(GoodsReceiptMarkedAsReceived(
goodsReceiptNumber: event.goodsReceiptNumber));
},
).catchError(
(error) {
emit(
const GoodsReceiptMarkedAsReceivedError(
message: "Error marking goods receipt as received."),
);
},
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ abstract class GoodsReceiptEvent {
class GetGoodsReceiptsEvent extends GoodsReceiptEvent {
const GetGoodsReceiptsEvent();
}

class MarkAsReceivedEvent extends GoodsReceiptEvent {
final String goodsReceiptNumber;
const MarkAsReceivedEvent(this.goodsReceiptNumber);
}
Loading

0 comments on commit dc83416

Please sign in to comment.